ControlParameter 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ControlParameter 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| 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建構子建立的物件會以所有屬性的預設值初始化。
ControlID與PropertyName屬性初始化為 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、 PropertyName、 Name和 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 控制從網頁表單頁面輸入資料庫資料。
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 建構子建立兩個 ControlParameter 物件,並將它們與 SqlDataSource 控制項關聯。
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建構子建立的物件會以指定的參數名稱、 Type、 和 ControlPropertyName 屬性初始化。 只有 和 ConvertEmptyStringToNull 屬性Direction會以預設值初始化。