Edit

Share 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();

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>

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

ControlParameter(ControlParameter)

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

protected ControlParameter(System.Web.UI.WebControls.ControlParameter original);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, string controlID);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, string controlID, string propertyName);

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;
    }
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, System.Data.DbType dbType, string controlID, string propertyName);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, TypeCode type, string controlID, string propertyName);

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);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1