FormParameter 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 FormParameter 类的新实例。
重载
FormParameter() |
初始化 FormParameter 类的未命名新实例。 |
FormParameter(FormParameter) |
使用 |
FormParameter(String, String) |
使用指定字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的一个新的已命名的实例。 |
FormParameter(String, DbType, String) |
通过使用指定的字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的新实例。 |
FormParameter(String, TypeCode, String) |
使用指定字符串标识要绑定到的窗体变量,初始化 FormParameter 类的一个新的已命名的强类型实例。 |
FormParameter()
初始化 FormParameter 类的未命名新实例。
public:
FormParameter();
public FormParameter ();
Public Sub New ()
示例
重要
FormParameter不会以任何方式验证 form 元素传递的值;它使用原始值。 在大多数情况下,可以通过处理事件(例如 Inserting
Selecting
Updating
,、、 或 Deleting
所使用的数据源控件公开的事件),在数据源控件使用它之前验证 FormParameter 的值。 如果 参数的值未通过验证测试,可以通过将关联CancelEventArgs类的 属性设置为 Canceltrue
来取消数据操作。
<%@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 构造函数创建的 对象使用其所有属性的默认值进行初始化。 初始化 FormField 为 String.Empty。 此外,属性 Name 初始化为 String.Empty, Type 属性初始化为 TypeCode.Object, Direction 属性初始化为 ,属性初始化为 Input,属性 DefaultValue 初始化为 visual Basic) 中的 null (Nothing
。
另请参阅
适用于
FormParameter(FormParameter)
使用 original
参数指定的实例的值初始化 FormParameter 类的新实例。
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 实例,将从该实例初始化当前实例。
注解
构造 FormParameter 函数是 protected
用于克隆实例的 FormParameter 复制构造函数。 、(包括 FormField、 Name和 Type )的值FormParameter全部传输到新实例。
另请参阅
适用于
FormParameter(String, String)
使用指定字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的一个新的已命名的实例。
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
参数的名称。
示例
重要
FormParameter不会以任何方式验证 form 元素传递的值;它使用原始值。 在大多数情况下,可以通过处理事件(例如 Inserting
Selecting
Updating
,、、 或 Deleting
所使用的数据源控件公开的事件),在数据源控件使用它之前验证 FormParameter 的值。 如果 参数的值未通过验证测试,可以通过将关联CancelEventArgs类的 属性设置为 Canceltrue
来取消数据操作。
<%@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构造函数创建的对象使用指定的参数名称和字符串进行初始化,该参数标识该参数绑定到的窗体变量。 使用 Type 默认值初始化 和 Direction 属性。
另请参阅
适用于
FormParameter(String, DbType, String)
通过使用指定的字符串标识要绑定到的窗体变量字段,初始化 FormParameter 类的新实例。
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
参数的名称。
- dbType
- DbType
参数的数据库类型。
- formField
- String
将参数对象绑定到的窗体变量的名称。
适用于
FormParameter(String, TypeCode, String)
使用指定字符串标识要绑定到的窗体变量,初始化 FormParameter 类的一个新的已命名的强类型实例。
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
参数的名称。
示例
重要
FormParameter不会以任何方式验证 form 元素传递的值;它使用原始值。 在大多数情况下,可以通过处理事件(例如 Inserting
Selecting
Updating
,、、 或 Deleting
所使用的数据源控件公开的事件),在数据源控件使用它之前验证 FormParameter 的值。 如果 参数的值未通过验证测试,可以通过将关联CancelEventArgs类的 属性设置为 Canceltrue
来取消数据操作。
<%@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该字符串标识该参数绑定到的窗体变量。 仅 使用 Direction 默认值初始化 和 ConvertEmptyStringToNull 属性。