次の方法で共有


ControlParameter コンストラクター

定義

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 オブジェクトは、DropDownList コントロールのSelectedValue プロパティを、DataGrid コントロールに表示されるデータを取得するパラメーター化された SQL クエリにバインドします。

<%@ 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 インスタンスの複製に使用される保護されたコピー コンストラクターです。 ControlIDPropertyNameNameTypeのプロパティなど、ControlParameter オブジェクトの値はすべて新しいインスタンスに転送されます。

こちらもご覧ください

適用対象

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

パラメーターの名前。

controlID
String

パラメーターがバインドされているコントロールの名前。 既定値は、Empty です。

注釈

ControlParameter コンストラクターを使用して作成されたControlParameter オブジェクトは、指定されたパラメーター名とControl名で初期化され、パラメーターのバインド先のControlが識別されます。 PropertyNameTypeDirectionなど、その他のプロパティは既定値で初期化されます。

こちらもご覧ください

適用対象

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

パラメーターの名前。

controlID
String

パラメーターがバインドされているコントロールの名前。 既定値は、Empty です。

propertyName
String

パラメーターがバインドされているコントロールのプロパティの名前。 既定値は、Empty です。

次のコードは、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名、およびパラメーターのバインド先のControlを識別するPropertyName プロパティで初期化されます。 TypeDirectionConvertEmptyStringToNullなど、その他のプロパティは既定値で初期化されます。

こちらもご覧ください

適用対象

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

パラメーターのデータ型。

controlID
String

パラメーターがバインドされているコントロールの名前。 既定値は、Empty です。

propertyName
String

パラメーターがバインドされているコントロールのプロパティの名前。 既定値は、Empty です。

適用対象

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

パラメーターの名前。

type
TypeCode

パラメーターが表す型。 既定値は、Object です。

controlID
String

パラメーターがバインドされているコントロールの名前。 既定値は、Empty です。

propertyName
String

パラメーターがバインドされているコントロールのプロパティの名前。 既定値は、Empty です。

次のコードは、 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);


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 プロパティだけです。

こちらもご覧ください

適用対象