ControlParameter 类

定义

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
继承
ControlParameter

示例

下面的代码示例演示如何使用对象将 ControlParameter 控件中显示的数据绑定 ListBoxDropDownList 声明性方案中的控件的所选值。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. ControlParameter对象将添加到 SelectParameters SqlDataSource 窗体上的控件的集合,并对应于属性中的 " @Title " 占位符文本 SelectCommandThe 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 类将属性的值( ControlSelectedValue 或)绑定 SelectedIndex 到在参数化 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.

ControlParameter除了从类继承的属性以外,类还提供两个属性 ParameterControlIDPropertyNameThe ControlParameter class provides two properties in addition to those inherited from the Parameter class: ControlID and PropertyName. ControlID属性标识要 Control 绑定到的实例, PropertyName 属性标识 Control 类从中检索值的的公共属性 ControlParameterThe 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 类的未命名新实例。Initializes a new unnamed instance of the ControlParameter class.

ControlParameter(ControlParameter)

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

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 类的新的命名实例。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 类的新的命名实例。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 类的新命名的、强类型的实例。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

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

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.

(继承自 Parameter)
DbType

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

(继承自 Parameter)
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.

(继承自 Parameter)
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.

(继承自 Parameter)
IsTrackingViewState

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

(继承自 Parameter)
Name

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

(继承自 Parameter)
PropertyName

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

Size

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

(继承自 Parameter)
Type

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

(继承自 Parameter)
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.

(继承自 Parameter)

方法

Clone()

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

Equals(Object)

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

(继承自 Object)
Evaluate(HttpContext, Control)

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

GetDatabaseType()

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

(继承自 Parameter)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
LoadViewState(Object)

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

(继承自 Parameter)
MemberwiseClone()

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

(继承自 Object)
OnParameterChanged()

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

(继承自 Parameter)
SaveViewState()

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

(继承自 Parameter)
SetDirty()

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

(继承自 Parameter)
ToString()

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

(继承自 Parameter)
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.

(继承自 Parameter)

显式接口实现

ICloneable.Clone()

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

(继承自 Parameter)
IStateManager.IsTrackingViewState

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

(继承自 Parameter)
IStateManager.LoadViewState(Object)

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

(继承自 Parameter)
IStateManager.SaveViewState()

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

(继承自 Parameter)
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.

(继承自 Parameter)

适用于

另请参阅