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 屬性的值( Control 例如或)系結 SelectedValue 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 ControlParameter 值。The 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 物件繫結至的值轉換成 null (如果其為 Empty)。Gets 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 值,該值等於目前 Parameter 執行個體的 CLR 型別。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)

適用於

另請參閱