ParameterCollection ParameterCollection ParameterCollection ParameterCollection Class

定義

代表進階資料繫結案例中資料來源控制項所使用之 ParameterParameter 衍生物件的集合。Represents a collection of Parameter and Parameter-derived objects that are used by data source controls in advanced data-binding scenarios.

public ref class ParameterCollection : System::Web::UI::StateManagedCollection
public class ParameterCollection : System.Web.UI.StateManagedCollection
type ParameterCollection = class
    inherit StateManagedCollection
Public Class ParameterCollection
Inherits StateManagedCollection
繼承
ParameterCollectionParameterCollectionParameterCollectionParameterCollection

範例

下列程式碼範例示範如何使用AccessDataSource控制項FormParameter和, 在GridView控制項中顯示 Microsoft Access 資料庫的資訊。The following code example demonstrates how to use an AccessDataSource control and a FormParameter to display information from a Microsoft Access database in a GridView control. SelectParameters使用FormParameter 方法Add , 將物件加入至集合。The FormParameter object is added to the SelectParameters collection using the Add method.

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。This example has a text box that accepts user input, which is a potential security threat. 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。For more information, see Script Exploits Overview.

<%@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>

備註

類別代表在具有資料來源Parameter控制項的高階資料系結案例中使用的物件集合。 ParameterCollectionThe ParameterCollection class represents a collection of Parameter objects used in advanced data-binding scenarios with data source controls. 物件是用來在抓取、更新、刪除和Page插入資料時, 將本機變數、HTTP cookie、會話變數和其他控制項值所包含的值系結至資料來源控制項。 ParameterThe Parameter objects are used to bind the values contained by local Page variables, HTTP cookies, session variables, and other controls' values to data source controls when retrieving, updating, deleting, and inserting data.

使用類別, 以程式設計方式管理一Parameter組物件。 ParameterCollectionUse the ParameterCollection class to programmatically manage a set of Parameter objects. 您可以使用ParameterCollection類別的適當方法來Parameter新增、插入和移除物件。You can add, insert, and remove Parameter objects using the appropriate methods of the ParameterCollection class. 若要以Parameter程式設計方式從集合中取出物件, 請使用下列其中一種方法:To programmatically retrieve Parameter objects from a collection, use one of following methods:

Count屬性會指定集合中的專案總數, 並且用來判斷集合的上限。The Count property specifies the total number of items in the collection, and is used to determine the upper bound of the collection. Add可以使用Insert 、、RemoveAt和方法,在集合中加入和移除專案。RemoveYou can add and remove items from the collection by using the Add, Insert, Remove, and RemoveAt methods.

根據特定資料來源控制項的執行和語義而定, 參數儲存在ParameterCollection集合中的順序可能很重要。Depending on the implementation and the semantics of a particular data source control, the order in which the parameters are stored in the ParameterCollection collection might be important. 例如, 當您使用SqlDataSource控制項做為 ODBC 資料來源時, ParameterCollection集合中的Parameter物件順序必須與您使用之參數化 SQL 查詢中參數的順序相同。For example, when using the SqlDataSource control as an ODBC data source, the order of the Parameter objects in the ParameterCollection collection must be the same as the order of the parameters in the parameterized SQL queries you use. 不過, 將SqlDataSource控制項與 Microsoft SQL Server 搭配使用時, Parameter物件的順序並不重要。However, when using the SqlDataSource control with Microsoft SQL Server, the order of the Parameter objects are not important.

重要

當您使用資料來源控制項時, 會在沒有驗證的情況下將值插入命令參數中, 這是潛在的安全性威脅。When you use data source controls, values are inserted into command parameters without validation, which is a potential security threat. 在執行命令之前, 使用資料來源控制項中的事件來驗證參數值。Use an event in the data source control to validate parameter values before the command is executed. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。For more information, see Script Exploits Overview.

下表列出不同的參數類別, 以及它們的使用方式。The following table lists the different parameter classes and how they are used.

參數類別Parameter Class 說明Description
Parameter 基底參數類別。The base parameter class. 用來系結至本機變數或使用屬性的DefaultValue任何靜態字串。Use it to bind to a local variable or any static string using the DefaultValue property.
ControlParameter 參數, 可以用來系結至控制項的屬性或方法傳回值。A parameter that can be used to bind to a control's property or method return value.
CookieParameter 可以用來系結至 cookie 值的參數。A parameter that can be used to bind to the value of a cookie.
FormParameter 參數, 可以用來系結至目前 Web form 頁面的屬性。A parameter that can be used to bind to an attribute of the current Web Forms page.
QueryStringParameter 參數, 可用於系結至查詢字串上傳遞至 Web form 頁面的值。A parameter that can be used to bind to a value passed to a Web Forms page on a query string.
SessionParameter 可以用來系結至會話變數值的參數。A parameter that can be used to bind to the value of a session variable.
ProfileParameter 參數, 可用於系結至 ASP.NET 配置檔案屬性的值。A parameter that can be used to bind to the value of an ASP.NET Profile property.

建構函式

ParameterCollection() ParameterCollection() ParameterCollection() ParameterCollection()

初始化這個類別,以供繼承的類別執行個體使用。Initializes the class for use by an inherited class instance. 此建構函式只能由繼承的類別呼叫。This constructor can be called only by an inherited class.

屬性

Count Count Count Count

取得 StateManagedCollection 集合中所包含的項目數。Gets the number of elements contained in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
ICollection.Count ICollection.Count ICollection.Count ICollection.Count

取得 StateManagedCollection 集合中所包含的項目數。Gets the number of elements contained in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

取得值,表示 StateManagedCollection 集合是否為同步 (安全執行緒)。Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). 在所有情況下,這個方法都會傳回 falseThis method returns false in all cases.

(Inherited from StateManagedCollection)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

取得物件,這個物件可以用來對 StateManagedCollection 集合進行同步存取。Gets an object that can be used to synchronize access to the StateManagedCollection collection. 在所有情況下,這個方法都會傳回 nullThis method returns null in all cases.

(Inherited from StateManagedCollection)
IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

取得值,表示 StateManagedCollection 集合是否具有固定大小。Gets a value indicating whether the StateManagedCollection collection has a fixed size. 在所有情況下,這個方法都會傳回 falseThis method returns false in all cases.

(Inherited from StateManagedCollection)
IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

取得值,表示 StateManagedCollection 集合是否為唯讀。Gets a value indicating whether the StateManagedCollection collection is read-only.

(Inherited from StateManagedCollection)
IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

取得在指定索引處的 IStateManager 項目。Gets the IStateManager element at the specified index.

(Inherited from StateManagedCollection)
IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState

取得值,表示 StateManagedCollection 集合是否正在儲存變更至檢視狀態。Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

(Inherited from StateManagedCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

取得或設定位於集合中所指定索引處的 Parameter 物件。Gets or sets the Parameter object at the specified index in the collection.

Item[String] Item[String] Item[String] Item[String]

取得或設定集合中具有指定名稱的 Parameter 物件。Gets or sets the Parameter object with the specified name in the collection.

方法

Add(Parameter) Add(Parameter) Add(Parameter) Add(Parameter)

將指定的 Parameter 物件附加到集合的結尾。Appends the specified Parameter object to the end of the collection.

Add(String, DbType, String) Add(String, DbType, String) Add(String, DbType, String) Add(String, DbType, String)

使用指定的名稱、資料庫型別及預設值建立 Parameter 物件,並將它加入集合的結尾。Creates a Parameter object with the specified name, database type, and default value, and adds it to the end of the collection.

Add(String, String) Add(String, String) Add(String, String) Add(String, String)

以指定的名稱和預設值建立 Parameter 物件,並將其附加至集合結尾。Creates a Parameter object with the specified name and default value, and appends it to the end of the collection.

Add(String, TypeCode, String) Add(String, TypeCode, String) Add(String, TypeCode, String) Add(String, TypeCode, String)

以指定的名稱、Parameter 和預設值建立 TypeCode 物件,並將其附加至集合結尾。Creates a Parameter object with the specified name, TypeCode, and default value, and appends it to the end of the collection.

Clear() Clear() Clear() Clear()

將所有項目從 StateManagedCollection 集合中移除。Removes all items from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
Contains(Parameter) Contains(Parameter) Contains(Parameter) Contains(Parameter)

決定 ParameterCollection 集合是否包含特定值。Determines whether the ParameterCollection collection contains a specific value

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

從特定的陣列索引開始,將 StateManagedCollection 集合的項目複製到陣列。Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(Inherited from StateManagedCollection)
CopyTo(Parameter[], Int32) CopyTo(Parameter[], Int32) CopyTo(Parameter[], Int32) CopyTo(Parameter[], Int32)

將參數陣列的指定索引複製到參數集合。Copies a specified index of a parameter array to the parameter collection.

CreateKnownType(Int32) CreateKnownType(Int32) CreateKnownType(Int32) CreateKnownType(Int32)

建立預設 Parameter 物件的執行個體。Creates an instance of a default Parameter object.

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

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。Returns an iterator that iterates through the StateManagedCollection collection.

(Inherited from StateManagedCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetKnownTypes() GetKnownTypes() GetKnownTypes() GetKnownTypes()

取得 Parameter 集合可包含之 ParameterCollection 型別的陣列。Gets an array of Parameter types that the ParameterCollection collection can contain.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

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

取得已排序 Parameter 物件名稱集合和該集合目前包含的對應值。Gets an ordered collection of Parameter object names and their corresponding values currently contained by the collection.

IndexOf(Parameter) IndexOf(Parameter) IndexOf(Parameter) IndexOf(Parameter)

決定 Parameter 集合中之指定 ParameterCollection 物件的索引。Determines the index of a specified Parameter object in the ParameterCollection collection.

Insert(Int32, Parameter) Insert(Int32, Parameter) Insert(Int32, Parameter) Insert(Int32, Parameter)

將指定的 Parameter 物件插入 ParameterCollection 集合中的指定索引處。Inserts the specified Parameter object into the ParameterCollection collection at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnClear() OnClear() OnClear() OnClear()

在衍生類別中覆寫時,在 Clear() 方法移除集合的所有項目之前,執行額外工作。When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(Inherited from StateManagedCollection)
OnClearComplete() OnClearComplete() OnClearComplete() OnClearComplete()

清除集合的內容之後,執行額外的自訂處理程序。Performs additional custom processes after clearing the contents of the collection.

OnInsert(Int32, Object) OnInsert(Int32, Object) OnInsert(Int32, Object) OnInsert(Int32, Object)

在呼叫 Insert(Int32, Parameter) 方法之前發生。Occurs before the Insert(Int32, Parameter) method is called.

OnInsertComplete(Int32, Object) OnInsertComplete(Int32, Object) OnInsertComplete(Int32, Object) OnInsertComplete(Int32, Object)

Insert(Int32, Parameter) 方法完成之後發生。Occurs after the Insert(Int32, Parameter) method completes.

OnParametersChanged(EventArgs) OnParametersChanged(EventArgs) OnParametersChanged(EventArgs) OnParametersChanged(EventArgs)

引發 ParametersChanged 事件。Raises the ParametersChanged event.

OnRemove(Int32, Object) OnRemove(Int32, Object) OnRemove(Int32, Object) OnRemove(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之前,執行額外工作。When overridden in a derived class, performs additional work before the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(Inherited from StateManagedCollection)
OnRemoveComplete(Int32, Object) OnRemoveComplete(Int32, Object) OnRemoveComplete(Int32, Object) OnRemoveComplete(Int32, Object)

Remove(Parameter) 方法完成之後發生。Occurs after the Remove(Parameter) method completes.

OnValidate(Object) OnValidate(Object) OnValidate(Object) OnValidate(Object)

當驗證數值時,執行額外的自訂處理序。Performs additional custom processes when validating a value.

Remove(Parameter) Remove(Parameter) Remove(Parameter) Remove(Parameter)

Parameter 集合中移除指定的 ParameterCollection 物件。Removes the specified Parameter object from the ParameterCollection collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Parameter 集合中移除指定索引處的 ParameterCollection 物件。Removes the Parameter object at the specified index from the ParameterCollection collection.

SetDirty() SetDirty() SetDirty() SetDirty()

強制整個 StateManagedCollection 集合序列化至檢視狀態。Forces the entire StateManagedCollection collection to be serialized into view state.

(Inherited from StateManagedCollection)
SetDirtyObject(Object) SetDirtyObject(Object) SetDirtyObject(Object) SetDirtyObject(Object)

將指定的 Parameter 物件標記為已經變更 (自從上次從檢視狀態載入或儲存後)。Marks the specified Parameter object as having changed since the last load or save from view state.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

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

逐一查看集合所包含的 Parameter 物件,並針對每個物件呼叫 Evaluate 方法。Iterates through the Parameter objects contained by the collection, and calls the Evaluate method on each one.

事件

ParametersChanged ParametersChanged ParametersChanged ParametersChanged

當集合所包含的一個或多個 Parameter 物件變更狀態時發生。Occurs when one or more Parameter objects contained by the collection changes state.

明確介面實作

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。Returns an iterator that iterates through the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

將項目加入 StateManagedCollection 集合。Adds an item to the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Clear() IList.Clear() IList.Clear() IList.Clear()

將所有項目從 StateManagedCollection 集合中移除。Removes all items from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

判斷 StateManagedCollection 集合是否包含特定值。Determines whether the StateManagedCollection collection contains a specific value.

(Inherited from StateManagedCollection)
IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

判斷 StateManagedCollection 集合中指定之項目的索引。Determines the index of a specified item in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

將項目插入位於指定索引處的 StateManagedCollection 集合中。Inserts an item into the StateManagedCollection collection at the specified index.

(Inherited from StateManagedCollection)
IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

StateManagedCollection 集合中移除指定物件的第一個符合項目。Removes the first occurrence of the specified object from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

移除指定索引處的 IStateManager 項目。Removes the IStateManager element at the specified index.

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

還原先前儲存之 StateManagedCollection 集合和內含 IStateManager 項目的檢視狀態。Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

(Inherited from StateManagedCollection)
IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來 StateManagedCollection 集合和每個內含 IStateManager 物件的變更。Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

(Inherited from StateManagedCollection)
IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState()

使得 StateManagedCollection 集合和每個內含 IStateManager 物件追蹤其檢視狀態的變更,以便跨相同頁面要求保存這些變更。Causes the StateManagedCollection collection and each of the IStateManager objects it contains to track changes to their view state so they can be persisted across requests for the same page.

(Inherited from StateManagedCollection)

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱