Bewerken

Delen via


ControlParameter Constructors

Definition

Initializes a new instance of the ControlParameter class.

Overloads

ControlParameter()

Initializes a new unnamed instance of the ControlParameter class.

ControlParameter(ControlParameter)

Initializes a new instance of the ControlParameter class with values from the specified instance.

ControlParameter(String, String)

Initializes a new named instance of the ControlParameter class, using the specified control name to identify which control to bind to.

ControlParameter(String, String, String)

Initializes a new named instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

ControlParameter(String, DbType, String, String)

Initializes a new instance of the ControlParameter class by using the specified parameter name, database type, control ID, and property name.

ControlParameter(String, TypeCode, String, String)

Initializes a new named and strongly typed instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

ControlParameter()

Initializes a new unnamed instance of the ControlParameter class.

public:
 ControlParameter();
public ControlParameter ();
Public Sub New ()

Examples

The following code shows how to create a ControlParameter object with the ControlParameter constructor. The ControlParameter object binds the SelectedValue property of a DropDownList control to a parameterized SQL query that retrieves data that is displayed in a DataGrid control.

<%@ Page Language="C#" CodeFile="param1acs.aspx.cs" Inherits="param1acs_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList
          runat="server"
          AutoPostBack="True"
          id="DropDownList1">
            <asp:ListItem Value="USA">USA</asp:ListItem>
            <asp:ListItem Value="UK">UK</asp:ListItem>
         </asp:DropDownList>

        <asp:DataGrid
          runat="server"
          id="DataGrid1" />    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="param1avb.aspx.vb" Inherits="param1avb_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList
          runat="server"
          AutoPostBack="True"
          id="DropDownList1">
            <asp:ListItem Value="USA">USA</asp:ListItem>
            <asp:ListItem Value="UK">UK</asp:ListItem>
         </asp:DropDownList>

        <asp:DataGrid
          runat="server"
          id="DataGrid1" />    
    </div>
    </form>
</body>
</html>

Remarks

A ControlParameter object that is created with the ControlParameter constructor is initialized with default values for all its properties. The ControlID and PropertyName properties are initialized to String.Empty. In addition, the Name property is initialized to String.Empty, the Type property is initialized to TypeCode.Object, the Direction property is initialized to Input, and the DefaultValue property is initialized to null.

Applies to

ControlParameter(ControlParameter)

Initializes a new instance of the ControlParameter class with values from the specified instance.

protected:
 ControlParameter(System::Web::UI::WebControls::ControlParameter ^ original);
protected ControlParameter (System.Web.UI.WebControls.ControlParameter original);
new System.Web.UI.WebControls.ControlParameter : System.Web.UI.WebControls.ControlParameter -> System.Web.UI.WebControls.ControlParameter
Protected Sub New (original As ControlParameter)

Parameters

original
ControlParameter

A ControlParameter instance from which the current instance is initialized.

Remarks

The ControlParameter constructor is a protected copy constructor that is used to clone a ControlParameter instance. The values of the ControlParameter object, including the ControlID, PropertyName, Name, and Type properties, are all transferred to the new instance.

See also

Applies to

ControlParameter(String, String)

Initializes a new named instance of the ControlParameter class, using the specified control name to identify which control to bind to.

public:
 ControlParameter(System::String ^ name, System::String ^ controlID);
public ControlParameter (string name, string controlID);
new System.Web.UI.WebControls.ControlParameter : string * string -> System.Web.UI.WebControls.ControlParameter
Public Sub New (name As String, controlID As String)

Parameters

name
String

The name of the parameter.

controlID
String

The name of the control that the parameter is bound to. The default is Empty.

Remarks

A ControlParameter object that is created with the ControlParameter constructor is initialized with the specified parameter name and Control name, which identifies the Control that the parameter binds to. Other properties, including PropertyName, Type, and Direction, are initialized with default values.

See also

Applies to

ControlParameter(String, String, String)

Initializes a new named instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

public:
 ControlParameter(System::String ^ name, System::String ^ controlID, System::String ^ propertyName);
public ControlParameter (string name, string controlID, string propertyName);
new System.Web.UI.WebControls.ControlParameter : string * string * string -> System.Web.UI.WebControls.ControlParameter
Public Sub New (name As String, controlID As String, propertyName As String)

Parameters

name
String

The name of the parameter.

controlID
String

The name of the control that the parameter is bound to. The default is Empty.

propertyName
String

The name of the property on the control that the parameter is bound to. The default is Empty.

Examples

The following code shows how to create ControlParameter objects by using the ControlParameter constructor. The parameters bind to the values of TextBox and DropDownList controls to enter data in a database from a Web Forms page.

private void Button1_Click(object sender, EventArgs e) {

    // The user has pressed the Submit button, prepare a parameterized
    // SQL query to insert the values from the controls.
    AccessDataSource1.InsertCommand =
    "INSERT INTO Employees (FirstName,LastName,Address,City,PostalCode,Country,ReportsTo) " +
    "  VALUES (?,?,?,?,?,?,? ); ";

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("FirstName", "TextBox1", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("LastName", "TextBox2", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("Address", "TextBox3", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("City", "TextBox4", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("PostalCode", "TextBox5", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("Country", "TextBox6", "Text"));

    AccessDataSource1.InsertParameters.Add(
      new ControlParameter("ReportsTo", "DropDownList1", "SelectedValue"));

    try {
        AccessDataSource1.Insert();
    }
    finally {
        Button1.Visible = false;
        Label9.Visible = true;
    }
}
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    ' The user has pressed the Submit button, prepare a parameterized
    ' SQL query to insert the values from the controls.
    AccessDataSource1.InsertCommand = _
    "INSERT INTO Employees (FirstName,LastName,Address,City,PostalCode,Country,ReportsTo) " & _
    "  VALUES (?,?,?,?,?,?,? ); "

    Dim firstName As New ControlParameter("FirstName", "TextBox1", "Text")
    AccessDataSource1.InsertParameters.Add(firstName)

    Dim lastName As New ControlParameter("LastName", "TextBox2", "Text")
    AccessDataSource1.InsertParameters.Add(lastName)

    Dim address As New ControlParameter("Address", "TextBox3", "Text")
    AccessDataSource1.InsertParameters.Add(address)

    Dim city As New ControlParameter("City", "TextBox4", "Text")
    AccessDataSource1.InsertParameters.Add(city)

    Dim postalCode As New ControlParameter("PostalCode", "TextBox5", "Text")
    AccessDataSource1.InsertParameters.Add(postalCode)

    Dim country As New ControlParameter("Country", "TextBox6", "Text")
    AccessDataSource1.InsertParameters.Add(country)

    Dim supervisor As New ControlParameter("ReportsTo", "DropDownList1", "SelectedValue")
    AccessDataSource1.InsertParameters.Add(supervisor)

    Try
        AccessDataSource1.Insert()
    Finally
        Button1.Visible = False
        Label9.Visible = True
    End Try

End Sub

Remarks

A ControlParameter object that is created with the ControlParameter constructor is initialized with the specified parameter name, Control name, and PropertyName property, which identifies the Control that the parameter binds to. Other properties, including Type, Direction, and ConvertEmptyStringToNull, are initialized with default values.

See also

Applies to

ControlParameter(String, DbType, String, String)

Initializes a new instance of the ControlParameter class by using the specified parameter name, database type, control ID, and property name.

public:
 ControlParameter(System::String ^ name, System::Data::DbType dbType, System::String ^ controlID, System::String ^ propertyName);
public ControlParameter (string name, System.Data.DbType dbType, string controlID, string propertyName);
new System.Web.UI.WebControls.ControlParameter : string * System.Data.DbType * string * string -> System.Web.UI.WebControls.ControlParameter
Public Sub New (name As String, dbType As DbType, controlID As String, propertyName As String)

Parameters

name
String

The name of the parameter.

dbType
DbType

The data type of the parameter.

controlID
String

The name of the control that the parameter is bound to. The default is Empty.

propertyName
String

The name of the property of the control that the parameter is bound to. The default is Empty.

Applies to

ControlParameter(String, TypeCode, String, String)

Initializes a new named and strongly typed instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

public:
 ControlParameter(System::String ^ name, TypeCode type, System::String ^ controlID, System::String ^ propertyName);
public ControlParameter (string name, TypeCode type, string controlID, string propertyName);
new System.Web.UI.WebControls.ControlParameter : string * TypeCode * string * string -> System.Web.UI.WebControls.ControlParameter
Public Sub New (name As String, type As TypeCode, controlID As String, propertyName As String)

Parameters

name
String

The name of the parameter.

type
TypeCode

The type that the parameter represents. The default is Object.

controlID
String

The name of the control that the parameter is bound to. The default is Empty.

propertyName
String

The name of the property of the control that the parameter is bound to. The default is Empty.

Examples

The following code shows how to use the ControlParameter constructor to create two ControlParameter objects and associate them with a SqlDataSource control.


ControlParameter country =
  new ControlParameter("country",TypeCode.String,"ListBox1","SelectedValue");
sqlSource.SelectParameters.Add(country);

ControlParameter report  =
  new ControlParameter("report",TypeCode.Int16,"ListBox2","SelectedValue");
sqlSource.SelectParameters.Add(report);


Dim country As ControlParameter
country = New ControlParameter("country", TypeCode.String, "ListBox1", "SelectedValue")

Dim report As ControlParameter
report = New ControlParameter("report", TypeCode.Int16, "ListBox2", "SelectedValue")

Remarks

A ControlParameter object that is created with the ControlParameter constructor is initialized with the specified parameter name, Type, Control name, and PropertyName property. Only the Direction and ConvertEmptyStringToNull properties are initialized with default values.

See also

Applies to