ControlParameter コンストラクタ ()
アセンブリ: System.Web (system.web.dll 内)


ControlParameter コンストラクタで作成された ControlParameter オブジェクトは、すべてのプロパティに既定値を使用して初期化されます。ControlID プロパティおよび PropertyName プロパティは String.Empty に初期化されています。また、Name プロパティは String.Empty に初期化され、Type プロパティは TypeCode.Object に初期化されます。さらに、Direction プロパティは Input に初期化され、DefaultValue プロパティは null 参照 (Visual Basic では Nothing) に初期化されます。

ControlParameter コンストラクタを使用して ControlParameter オブジェクトを作成する方法を次のコード例に示します。ControlParameter オブジェクトは、DropDownList コントロールの SelectedValue プロパティを、DataGrid コントロール内に表示されるデータを取得する、SQL パラメータ クエリにバインドします。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="param1avb.aspx.vb" Inherits="param1avb_aspx" %> <html > <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="C#" CodeFile="param1acs.aspx.cs" Inherits="param1acs_aspx" %> <html > <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="VJ#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <SCRIPT runat="server"> private void Page_Load(Object sender, System.EventArgs e) { SqlDataSource sqlSource = new SqlDataSource("Data Source=localhost;" + "Integrated Security=SSPI;Initial Catalog=Northwind;", "SELECT FirstName, LastName FROM Employees WHERE Country = @country;"); ControlParameter country = new ControlParameter(); country.set_Name("country"); country.set_Type(System.TypeCode.String); country.set_ControlID("DropDownList1"); country.set_PropertyName("SelectedValue"); // If the DefaultValue is not set, the DataGrid does not // display anything on the first page load. This is because // on the first page load, the DropDownList has no // selected item, and the ControlParameter evaluates to // String.Empty. country.set_DefaultValue("USA"); sqlSource.get_SelectParameters().Add(country); // Add the SqlDataSource to the page controls collection. get_Page().get_Controls().Add(sqlSource); DataGrid1.set_DataSource(sqlSource); DataGrid1.DataBind(); } //Page_Load </SCRIPT> <HTML> <BODY> <FORM runat="server"> <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" /> </FORM> </BODY> </HTML>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlParameter コンストラクタ (String, String, String)
アセンブリ: System.Web (system.web.dll 内)

Dim name As String Dim controlID As String Dim propertyName As String Dim instance As New ControlParameter(name, controlID, propertyName)

ControlParameter コンストラクタを使用して作成された ControlParameter オブジェクトは、指定されたパラメータ名、Control 名、およびパラメータのバインド先の Control を識別する PropertyName プロパティを使用して初期化されます。Type、Direction、および ConvertEmptyStringToNull を含むその他のプロパティは既定値を使用して初期化されます。

ControlParameter コンストラクタを使用して ControlParameter オブジェクトを作成する方法を次のコード例に示します。パラメータは、Web フォーム ページからデータベースにデータを入力するための、TextBox および DropDownList コントロールの値にバインドします。
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
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; } }
private void Button1_Click(Object sender, System.EventArgs e) { // The user has pressed the Submit button, prepare a parameterized // SQL query to insert the values from the controls. AccessDataSource1.set_InsertCommand("INSERT INTO Employees" + "(FirstName,LastName,Address,City,PostalCode,Country,ReportsTo) " + " VALUES (?,?,?,?,?,?,? ); "); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("FirstName", "TextBox1", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("LastName", "TextBox2", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("Address", "TextBox3", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("City", "TextBox4", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("PostalCode", "TextBox5", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("Country", "TextBox6", "Text")); AccessDataSource1.get_InsertParameters().Add(new ControlParameter ("ReportsTo", "DropDownList1", "SelectedValue")); try { AccessDataSource1.Insert(); } finally { Button1.set_Visible(false); Label9.set_Visible(true); } } //Button1_Click

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlParameter コンストラクタ (String, String)
アセンブリ: System.Web (system.web.dll 内)


ControlParameter コンストラクタを使用して作成された ControlParameter オブジェクトは、指定されたパラメータ名、およびパラメータのバインド先の Control を識別する Control 名を使用して初期化されます。PropertyName、Type、および Direction を含むその他のプロパティは既定値を使用して初期化されます。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlParameter コンストラクタ (String, TypeCode, String, String)
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ name As String, _ type As TypeCode, _ controlID As String, _ propertyName As String _ )
Dim name As String Dim type As TypeCode Dim controlID As String Dim propertyName As String Dim instance As New ControlParameter(name, type, controlID, propertyName)
public function ControlParameter ( name : String, type : TypeCode, controlID : String, propertyName : String )

ControlParameter コンストラクタを使用して作成された ControlParameter オブジェクトは、指定されたパラメータ名、Type、Control 名、および PropertyName プロパティを使用して初期化されます。Direction プロパティおよび ConvertEmptyStringToNull プロパティのみ既定値で初期化されます。

ControlParameter コンストラクタを使用して、2 つの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);
ControlParameter country = new ControlParameter("country", System.TypeCode.String, "ListBox1", "SelectedValue"); sqlSource.get_SelectParameters().Add(country); ControlParameter report = new ControlParameter("report", System.TypeCode.Int16, "ListBox2", "SelectedValue"); sqlSource.get_SelectParameters().Add(report);

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlParameter コンストラクタ (ControlParameter)
アセンブリ: System.Web (system.web.dll 内)


ControlParameter コンストラクタは、ControlParameter インスタンスのクローンを作成するための protected コピー コンストラクタです。ControlParameter オブジェクトの値 (ControlID、PropertyName、Name、Type プロパティなど) が、すべて新しいインスタンスに転送されます。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlParameter コンストラクタ

名前 | 説明 |
---|---|
ControlParameter () | ControlParameter クラスの名前のない新しいインスタンスを初期化します。 |
ControlParameter (ControlParameter) | original パラメータで指定されたインスタンスの値を使用して、ControlParameter クラスの新しいインスタンスを初期化します。 |
ControlParameter (String, String) | バインド先のコントロールを識別する指定されたコントロール名を使用して、ControlParameter クラスの名前付きの新しいインスタンスを初期化します。 |
ControlParameter (String, String, String) | 指定されたプロパティ名およびバインド先のコントロールを識別するコントロール名を使用して、ControlParameter クラスの名前付きの新しいインスタンスを初期化します。 |
ControlParameter (String, TypeCode, String, String) | 指定されたプロパティ名およびバインド先のコントロールを識別するコントロール名を使用して、ControlParameter クラスの厳密に型指定された名前付きの新しいインスタンスを初期化します。 |

- ControlParameter コンストラクタ ()のページへのリンク