ControlParameter ControlParameter ControlParameter ControlParameter Class

定义

Control 的属性值绑定到参数对象。Binds the value of a property of a Control to a parameter object.

public ref class ControlParameter : System::Web::UI::WebControls::Parameter
public class ControlParameter : System.Web.UI.WebControls.Parameter
type ControlParameter = class
    inherit Parameter
Public Class ControlParameter
Inherits Parameter
继承
ControlParameterControlParameterControlParameterControlParameter

示例

下面的代码示例演示如何使用ControlParameter对象将ListBox控件中显示的数据绑定到声明性方案中的DropDownList控件的所选值。The following code example demonstrates how to use a ControlParameter object to bind data displayed in a ListBox control to the selected value of a DropDownList control in a declarative scenario. SqlDataSource SelectParameters SelectCommand @Title对象将添加到窗体上的控件的集合,并对应于属性中的 "" 占位符文本。 ControlParameterThe ControlParameter object is added to the SelectParameters collection of the SqlDataSource control on the form, and corresponds to the "@Title" placeholder text in the SelectCommand property.

<!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">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

    </form>
  </body>
</html>
<!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">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

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

注解

您可以使用ControlParameter类将Control属性的值(如SelectedValueSelectedIndex)绑定到在参数化 SQL 查询、业务对象方法或筛选表达式中使用的参数。You can use the ControlParameter class to bind the value of a Control property, such as SelectedValue or SelectedIndex, to a parameter that is used in a parameterized SQL query, business object method, or filtering expression.

除了从类继承的属性以外, ControlID PropertyName类还提供两个ControlParameter属性 Parameter :和。The ControlParameter class provides two properties in addition to those inherited from the Parameter class: ControlID and PropertyName. PropertyName Control ControlParameter属性标识要绑定到的实例,属性标识类从中检索值的的公共属性。Control ControlIDThe ControlID property identifies which Control instance to bind to and the PropertyName property identifies the public property of the Control from which the ControlParameter class retrieves a value.

构造函数

ControlParameter() ControlParameter() ControlParameter() ControlParameter()

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

ControlParameter(ControlParameter) ControlParameter(ControlParameter) ControlParameter(ControlParameter) ControlParameter(ControlParameter)

使用指定实例中的值初始化 ControlParameter 类的新实例。Initializes a new instance of the ControlParameter class with values from the specified instance.

ControlParameter(String, DbType, String, String) ControlParameter(String, DbType, String, String) ControlParameter(String, DbType, String, String) ControlParameter(String, DbType, String, String)

使用指定的参数名称、数据库类型、控件 ID 以及属性名称初始化 ControlParameter 类的新实例。Initializes a new instance of the ControlParameter class by using the specified parameter name, database type, control ID, and property name.

ControlParameter(String, String) ControlParameter(String, String) ControlParameter(String, String) ControlParameter(String, String)

使用指定的控件名称(此名称标识要绑定到哪一个控件)初始化 ControlParameter 类的新的命名实例。Initializes a new named instance of the ControlParameter class, using the specified control name to identify which control to bind to.

ControlParameter(String, String, String) ControlParameter(String, String, String) ControlParameter(String, String, String) ControlParameter(String, String, String)

使用指定的属性名和控件名称(此名称标识要绑定到哪一个控件)初始化 ControlParameter 类的新的命名实例。Initializes a new named instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

ControlParameter(String, TypeCode, String, String) ControlParameter(String, TypeCode, String, String) ControlParameter(String, TypeCode, String, String) ControlParameter(String, TypeCode, String, String)

使用指定的属性名和控件名称(此名称标识绑定到哪一个控件)初始化 ControlParameter 类的新命名的、强类型的实例。Initializes a new named and strongly typed instance of the ControlParameter class, using the specified property name and control name to identify which control to bind to.

属性

ControlID ControlID ControlID ControlID

指定 ControlParameter 对象绑定到的控件名称。Specifies the name of the control that the ControlParameter object binds to.

ConvertEmptyStringToNull ConvertEmptyStringToNull ConvertEmptyStringToNull ConvertEmptyStringToNull

获取或设置一个值,该值指示在 Parameter 对象绑定到的值为 Empty 时是否应将其转换为 nullGets or sets a value indicating whether the value that the Parameter object is bound to should be converted to null if it is Empty.

(Inherited from Parameter)
DbType DbType DbType DbType

获取或设置参数的数据库类型。Gets or sets the database type of the parameter.

(Inherited from Parameter)
DefaultValue DefaultValue DefaultValue DefaultValue

指定参数的默认值(如果调用 Evaluate(HttpContext, Control) 方法时参数绑定到的值未被初始化)。Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate(HttpContext, Control) method is called.

(Inherited from Parameter)
Direction Direction Direction Direction

指示 Parameter 对象是否用于将值绑定到控件,或者是否可以使用控件更改值。Indicates whether the Parameter object is used to bind a value to a control, or the control can be used to change the value.

(Inherited from Parameter)
IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState

获取一个值,该值指示 Parameter 对象是否保存对其视图状态的更改。Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
IsTrackingViewState IsTrackingViewState IsTrackingViewState IsTrackingViewState

获取一个值,该值指示 Parameter 对象是否保存对其视图状态的更改。Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
Name Name Name Name

获取或设置参数的名称。Gets or sets the name of the parameter.

(Inherited from Parameter)
PropertyName PropertyName PropertyName PropertyName

获取或设置由 ControlID 对象绑定到的 ControlParameter 属性标识的控件的属性名。Gets or sets the property name of the control identified by the ControlID property that the ControlParameter object binds to.

Size Size Size Size

获取或设置参数的大小。Gets or sets the size of the parameter.

(Inherited from Parameter)
Type Type Type Type

获取或设置参数类型。Gets or sets the type of the parameter.

(Inherited from Parameter)
ViewState ViewState ViewState ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 Parameter 对象的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a Parameter object across multiple requests for the same page.

(Inherited from Parameter)

方法

Clone() Clone() Clone() Clone()

返回当前 ControlParameter 实例的副本。Returns a duplicate of the current ControlParameter instance.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Evaluate(HttpContext, Control) Evaluate(HttpContext, Control) Evaluate(HttpContext, Control) Evaluate(HttpContext, Control)

更新并返回 ControlParameter 对象的值。Updates and returns the value of the ControlParameter object.

GetDatabaseType() GetDatabaseType() GetDatabaseType() GetDatabaseType()

获取与当前 DbType 实例的 CLR 类型等效的 Parameter 值。Gets the DbType value that is equivalent to the CLR type of the current Parameter instance.

(Inherited from Parameter)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
LoadViewState(Object) LoadViewState(Object) LoadViewState(Object) LoadViewState(Object)

将数据源视图还原为保存过的前一视图状态。Restores the data source view's previously saved view state.

(Inherited from Parameter)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnParameterChanged() OnParameterChanged() OnParameterChanged() OnParameterChanged()

调用包含 OnParametersChanged(EventArgs) 对象的 ParameterCollection 集合的 Parameter 方法。Calls the OnParametersChanged(EventArgs) method of the ParameterCollection collection that contains the Parameter object.

(Inherited from Parameter)
SaveViewState() SaveViewState() SaveViewState() SaveViewState()

自页回发到服务器开始,将更改保存到 Parameter 对象的视图状态。Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
SetDirty() SetDirty() SetDirty() SetDirty()

标记 Parameter 对象,以便在视图状态中记录其状态。Marks the Parameter object so its state will be recorded in view state.

(Inherited from Parameter)
ToString() ToString() ToString() ToString()

将此实例的值转换为其等效的字符串表示形式。Converts the value of this instance to its equivalent string representation.

(Inherited from Parameter)
TrackViewState() TrackViewState() TrackViewState() TrackViewState()

使 Parameter 对象跟踪其视图状态更改,以便这些更改可以存储在控件的 ViewState 对象中并在同一页面的不同请求间保留。Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

显式界面实现

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

返回当前 Parameter 实例的副本。Returns a duplicate of the current Parameter instance.

(Inherited from Parameter)
IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object)

将数据源视图还原为保存过的前一视图状态。Restores the data source view's previously saved view state.

(Inherited from Parameter)
IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState()

自页回发到服务器开始,将更改保存到 Parameter 对象的视图状态。Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState()

使 Parameter 对象跟踪其视图状态更改,以便这些更改可以存储在控件的 ViewState 对象中并在同一页面的不同请求间保留。Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

适用于

另请参阅