ControlParameter 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ControlParameter 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| ControlParameter() |
初始化类的新未命名实例 ControlParameter 。 |
| ControlParameter(ControlParameter) |
使用指定实例中的值初始化类的新实例 ControlParameter 。 |
| ControlParameter(String, String) |
使用指定的控件名称标识要绑定到的 ControlParameter 控件,初始化类的新命名实例。 |
| ControlParameter(String, String, String) |
使用指定的属性名称和控件名称来标识要绑定到的控件,初始化类的新命名实例 ControlParameter 。 |
| ControlParameter(String, DbType, String, String) |
使用指定的参数名称、数据库类型、控件 ID 和属性名称初始化类的新实例 ControlParameter 。 |
| ControlParameter(String, TypeCode, String, String) |
使用指定的属性名称和控件名称来标识要绑定到的 ControlParameter 控件,初始化类的新命名和强类型实例。 |
ControlParameter()
初始化类的新未命名实例 ControlParameter 。
public:
ControlParameter();
public ControlParameter();
Public Sub New ()
示例
以下代码演示如何使用ControlParameter构造函数创建ControlParameter对象。 该 ControlParameter 对象将 SelectedValue 控件的属性 DropDownList 绑定到参数化 SQL 查询,该查询检索控件中显示的 DataGrid 数据。
<%@ 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>
注解
ControlParameter使用ControlParameter构造函数创建的对象使用其所有属性的默认值进行初始化。
PropertyName属性ControlID初始化为 String.Empty. 此外,属性 Name 初始化为 String.Empty, Type 属性初始化为 TypeCode.Object, Direction 属性初始化为 Input,并且属性 DefaultValue 初始化为 null。
适用于
ControlParameter(ControlParameter)
使用指定实例中的值初始化类的新实例 ControlParameter 。
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)
参数
- original
- ControlParameter
从 ControlParameter 中初始化当前实例的实例。
注解
构造 ControlParameter 函数是用于克隆 ControlParameter 实例的受保护复制构造函数。 对象的值ControlParameter(包括 ControlID、PropertyNameName属性和Type属性)全部传输到新实例。
另请参阅
适用于
ControlParameter(String, String)
使用指定的控件名称标识要绑定到的 ControlParameter 控件,初始化类的新命名实例。
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)
参数
- name
- String
参数的名称。
注解
ControlParameter使用ControlParameter构造函数创建的对象使用指定的参数名称和名称进行初始化,该名称Control标识Control参数绑定到的对象。 其他属性(包括 PropertyName、 Type和 Direction)使用默认值进行初始化。
另请参阅
适用于
ControlParameter(String, String, String)
使用指定的属性名称和控件名称来标识要绑定到的控件,初始化类的新命名实例 ControlParameter 。
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)
参数
- name
- String
参数的名称。
示例
以下代码演示如何使用ControlParameter构造函数创建ControlParameter对象。 参数绑定到值 TextBox 和 DropDownList 控件,以从 Web 窗体页在数据库中输入数据。
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
注解
ControlParameter使用ControlParameter构造函数创建的对象使用指定的参数名称、Control名称和属性进行初始化,该名称、PropertyName名称和属性标识Control参数绑定到的对象。 其他属性(包括 Type、 Direction和 ConvertEmptyStringToNull)使用默认值进行初始化。
另请参阅
适用于
ControlParameter(String, DbType, String, String)
使用指定的参数名称、数据库类型、控件 ID 和属性名称初始化类的新实例 ControlParameter 。
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)
参数
- name
- String
参数的名称。
- dbType
- DbType
参数的数据类型。
适用于
ControlParameter(String, TypeCode, String, String)
使用指定的属性名称和控件名称来标识要绑定到的 ControlParameter 控件,初始化类的新命名和强类型实例。
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)
参数
- name
- String
参数的名称。
示例
以下代码演示如何使用ControlParameter构造函数创建两个ControlParameterSqlDataSource对象并将其与控件相关联。
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")
注解
ControlParameter使用ControlParameter构造函数创建的对象使用指定的参数名称、TypeControl名称和PropertyName属性进行初始化。 仅使用 Direction 默认值初始化和 ConvertEmptyStringToNull 属性。