FormParameter 构造函数

定义

初始化 FormParameter 类的新实例。Initializes a new instance of the FormParameter class.

重载

FormParameter()

初始化 FormParameter 类的未命名新实例。Initializes a new unnamed instance of the FormParameter class.

FormParameter(FormParameter)

使用 original 参数指定的实例的值初始化 FormParameter 类的新实例。Initializes a new instance of the FormParameter class with the values of the instance specified by the original parameter.

FormParameter(String, String)

使用指定字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的一个新的已命名的实例。Initializes a new named instance of the FormParameter class, using the specified string to identify which form variable field to bind to.

FormParameter(String, DbType, String)

通过使用指定的字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的新实例。Initializes a new instance of the FormParameter class, using the specified string to identify which form variable field to bind to.

FormParameter(String, TypeCode, String)

使用指定字符串标识要绑定到的窗体变量,初始化 FormParameter 类的一个新的已命名的强类型实例。Initializes a new named and strongly typed instance of the FormParameter class, using the specified string to identify which form variable to bind to.

FormParameter()

初始化 FormParameter 类的未命名新实例。Initializes a new unnamed instance of the FormParameter class.

public:
 FormParameter();
public FormParameter ();
Public Sub New ()

示例

重要

FormParameter 会以任何方式验证窗体元素所传递的值; 它将使用原始值。The FormParameter does not validate the value passed by the form element in any way; it uses the raw value. 在大多数情况下,你可以 FormParameter 通过处理事件(例如 SelectingUpdating 你所使用的 Inserting Deleting 数据源控件公开的、、或事件)来验证数据源控件使用的值。In most cases, you can validate the value of the FormParameter before it is used by a data source control by handling an event, such as the Selecting, Updating, Inserting, or Deleting event exposed by the data source control you are using. 如果参数的值未通过验证测试,则可以通过将 Cancel 关联类的属性设置为来取消数据操作 CancelEventArgs trueIf the value of the parameter does not pass your validation tests, you can cancel the data operation by setting the Cancel property of the associated CancelEventArgs class to true.

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){

  // You can add a FormParameter to the AccessDataSource control's
  // SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear();

  // Security Note: The AccessDataSource uses a FormParameter,
  // Security Note: which does not perform validation of input from the client.
  // Security Note: To validate the value of the FormParameter,
  // Security Note: handle the Selecting event.

  FormParameter formParam = new FormParameter();
  formParam.Name="lastname";
  formParam.Type=TypeCode.String;
  formParam.FormField="LastNameBox";
  AccessDataSource1.SelectParameters.Add(formParam);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1" />

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Private Sub Page_Load(sender As Object, e As EventArgs)

  ' You can add a FormParameter to the AccessDataSource control's
  ' SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear()

  ' Security Note: The AccessDataSource uses a FormParameter,
  ' Security Note: which does not perform validation of input from the client.
  ' Security Note: To validate the value of the FormParameter,
  ' Security Note: handle the Selecting event.
  Dim formParam As New FormParameter()
  formParam.Name="lastname"
  formParam.Type=TypeCode.String
  formParam.FormField="LastNameBox"
  AccessDataSource1.SelectParameters.Add(formParam)

End Sub ' Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1" />

    </form>
  </body>
</html>

注解

FormParameter使用构造函数创建的对象的 FormParameter 所有属性的默认值都进行了初始化。A FormParameter object created with the FormParameter constructor is initialized with default values for all its properties. FormField 初始化为 String.EmptyThe FormField is initialized to String.Empty. 此外,将属性初始化为,将属性初始化为,将属性初始化为, Name String.Empty Type TypeCode.Object Direction Input 并将 DefaultValue 属性初始化为 null (Nothing Visual Basic) 。Additionally, 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 (Nothing in Visual Basic).

适用于

FormParameter(FormParameter)

使用 original 参数指定的实例的值初始化 FormParameter 类的新实例。Initializes a new instance of the FormParameter class with the values of the instance specified by the original parameter.

protected:
 FormParameter(System::Web::UI::WebControls::FormParameter ^ original);
protected FormParameter (System.Web.UI.WebControls.FormParameter original);
new System.Web.UI.WebControls.FormParameter : System.Web.UI.WebControls.FormParameter -> System.Web.UI.WebControls.FormParameter
Protected Sub New (original As FormParameter)

参数

original
FormParameter

一个 FormParameter 实例,将从该实例初始化当前实例。A FormParameter instance that the current instance is initialized from.

注解

FormParameter构造函数是 protected 用于克隆实例的复制构造函数 FormParameterThe FormParameter constructor is a protected copy constructor used to clone a FormParameter instance. 的值 FormParameter (包括 FormField 、和) Name Type 全部传输到新的实例。The values of the FormParameter, including FormField, Name, and Type are all transferred to the new instance.

另请参阅

适用于

FormParameter(String, String)

使用指定字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的一个新的已命名的实例。Initializes a new named instance of the FormParameter class, using the specified string to identify which form variable field to bind to.

public:
 FormParameter(System::String ^ name, System::String ^ formField);
public FormParameter (string name, string formField);
new System.Web.UI.WebControls.FormParameter : string * string -> System.Web.UI.WebControls.FormParameter
Public Sub New (name As String, formField As String)

参数

name
String

参数的名称。The name of the parameter.

formField
String

将参数对象绑定到的窗体变量的名称。The name of the form variable that the parameter object is bound to. 默认为 EmptyThe default is Empty.

示例

重要

FormParameter 会以任何方式验证窗体元素所传递的值; 它将使用原始值。The FormParameter does not validate the value passed by the form element in any way; it uses the raw value. 在大多数情况下,你可以 FormParameter 通过处理事件(例如 SelectingUpdating 你所使用的 Inserting Deleting 数据源控件公开的、、或事件)来验证数据源控件使用的值。In most cases, you can validate the value of the FormParameter before it is used by a data source control by handling an event, such as the Selecting, Updating, Inserting, or Deleting event exposed by the data source control you are using. 如果参数的值未通过验证测试,则可以通过将 Cancel 关联类的属性设置为来取消数据操作 CancelEventArgs trueIf the value of the parameter does not pass your validation tests, you can cancel the data operation by setting the Cancel property of the associated CancelEventArgs class to true.

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){

  // You can add a FormParameter to the AccessDataSource control's
  // SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear();

  // Security Note: The AccessDataSource uses a FormParameter,
  // Security Note: which does not perform validation of input from the client.
  // Security Note: To validate the value of the FormParameter,
  // Security Note: handle the Selecting event.

  FormParameter formParam = new FormParameter("lastname","LastNameBox");
  formParam.Type=TypeCode.String;
  AccessDataSource1.SelectParameters.Add(formParam);
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Private Sub Page_Load(sender As Object, e As EventArgs)

  ' You can add a FormParameter to the AccessDataSource control's
  ' SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear()

  ' Security Note: The AccessDataSource uses a FormParameter,
  ' Security Note: which does not perform validation of input from the client.
  ' Security Note: To validate the value of the FormParameter,
  ' Security Note: handle the Selecting event.

  Dim formParam As New FormParameter("lastname","LastNameBox")
  formParam.Type=TypeCode.String
  AccessDataSource1.SelectParameters.Add(formParam)
End Sub ' Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>

注解

FormParameter使用构造函数创建的对象 FormParameter 将使用指定的参数名称和标识参数绑定到的窗体变量的字符串来初始化。A FormParameter object created with the FormParameter constructor is initialized with the specified parameter name and string that identifies the form variable that the parameter binds to. Type Direction 用默认值初始化和属性。The Type and Direction properties are initialized with default values.

另请参阅

适用于

FormParameter(String, DbType, String)

通过使用指定的字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的新实例。Initializes a new instance of the FormParameter class, using the specified string to identify which form variable field to bind to.

public:
 FormParameter(System::String ^ name, System::Data::DbType dbType, System::String ^ formField);
public FormParameter (string name, System.Data.DbType dbType, string formField);
new System.Web.UI.WebControls.FormParameter : string * System.Data.DbType * string -> System.Web.UI.WebControls.FormParameter
Public Sub New (name As String, dbType As DbType, formField As String)

参数

name
String

参数的名称。The name of the parameter.

dbType
DbType

参数的数据库类型。The database type of the parameter.

formField
String

将参数对象绑定到的窗体变量的名称。The name of the form variable that the parameter object is bound to.

适用于

FormParameter(String, TypeCode, String)

使用指定字符串标识要绑定到的窗体变量,初始化 FormParameter 类的一个新的已命名的强类型实例。Initializes a new named and strongly typed instance of the FormParameter class, using the specified string to identify which form variable to bind to.

public:
 FormParameter(System::String ^ name, TypeCode type, System::String ^ formField);
public FormParameter (string name, TypeCode type, string formField);
new System.Web.UI.WebControls.FormParameter : string * TypeCode * string -> System.Web.UI.WebControls.FormParameter
Public Sub New (name As String, type As TypeCode, formField As String)

参数

name
String

参数的名称。The name of the parameter.

type
TypeCode

该参数所表示的类型。The type that the parameter represents. 默认为 ObjectThe default is Object.

formField
String

将参数对象绑定到的窗体变量的名称。The name of the form variable that the parameter object is bound to. 默认为 EmptyThe default is Empty.

示例

重要

FormParameter 会以任何方式验证窗体元素所传递的值; 它将使用原始值。The FormParameter does not validate the value passed by the form element in any way; it uses the raw value. 在大多数情况下,你可以 FormParameter 通过处理事件(例如 SelectingUpdating 你所使用的 Inserting Deleting 数据源控件公开的、、或事件)来验证数据源控件使用的值。In most cases, you can validate the value of the FormParameter before it is used by a data source control by handling an event, such as the Selecting, Updating, Inserting, or Deleting event exposed by the data source control you are using. 如果参数的值未通过验证测试,则可以通过将 Cancel 关联类的属性设置为来取消数据操作 CancelEventArgs trueIf the value of the parameter does not pass your validation tests, you can cancel the data operation by setting the Cancel property of the associated CancelEventArgs class to true.

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){

  // You can add a FormParameter to the AccessDataSource control's
  // SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear();

  // Security Note: The AccessDataSource uses a FormParameter,
  // Security Note: which does not perform validation of input from the client.
  // Security Note: To validate the value of the FormParameter,
  // Security Note: handle the Selecting event.

  FormParameter formParam = new FormParameter("lastname", TypeCode.String, "LastNameBox");
  AccessDataSource1.SelectParameters.Add(formParam);
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                          (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Private Sub Page_Load(sender As Object, e As EventArgs)

  ' You can add a FormParameter to the AccessDataSource control's
  ' SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear()

  ' Security Note: The AccessDataSource uses a FormParameter,
  ' Security Note: which does not perform validation of input from the client.
  ' Security Note: To validate the value of the FormParameter,
  ' Security Note: handle the Selecting event.

  Dim formParam As New FormParameter("lastname",TypeCode.String,"LastNameBox")
  AccessDataSource1.SelectParameters.Add(formParam)

End Sub ' Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                           (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>

注解

FormParameter使用构造函数创建的对象 FormParameter 使用指定的参数名称、和字符串进行初始化,该 Type 字符串标识参数绑定到的窗体变量。A FormParameter object created with the FormParameter constructor is initialized with the specified parameter name, Type, and string that identifies the form variable that the parameter binds to. Direction ConvertEmptyStringToNull 用默认值初始化和属性。Only the Direction and ConvertEmptyStringToNull properties are initialized with default values.

另请参阅

适用于