ParameterCollection 类

定义

表示由高级数据绑定方案中的数据源控件使用的 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
继承
ParameterCollection

示例

下面的代码示例演示如何使用 @no__t 0 控件和 @no__t 在 @no__t 的控件中显示 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. 使用 Add 方法将 @no__t 0 对象添加到 @no__t 集合。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 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述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>

注解

@No__t-0 类表示在具有数据源控件的高级数据绑定方案中使用的 @no__t 1 个对象的集合。The ParameterCollection class represents a collection of Parameter objects used in advanced data-binding scenarios with data source controls. 当检索、更新、删除和插入数据时,@no__t 0 对象用于将本地 @no__t 1 变量、HTTP cookie、会话变量和其他控件值包含的值绑定到数据源控件。The 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.

使用 ParameterCollection 类以编程方式管理一组 @no__t 的对象。Use the ParameterCollection class to programmatically manage a set of Parameter objects. 您可以使用 @no__t 1 类的适当方法,添加、插入和删除 @no__t 的对象。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:

  • 使用索引器可按名称或使用数组表示法获取集合中的单个 @no__t 0 对象。Use the indexer to get a single Parameter object from the collection, by name or using array notation.

  • 使用 GetEnumerator 方法创建 System.Collections.IEnumerator 实现的对象,然后可以使用该对象从集合中获取项。Use the GetEnumerator method to create a System.Collections.IEnumerator-implemented object, which can then be used to get items from the collection.

@No__t-0 属性指定集合中的总项数,并用于确定集合的上限。The Count property specifies the total number of items in the collection, and is used to determine the upper bound of the collection. 可以通过使用 AddInsertRemove 和 @no__t 3 方法,在集合中添加和移除项。You 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. 例如,使用 @no__t 0 控件作为 ODBC 数据源时,ParameterCollection 集合中 @no__t 的对象的顺序必须与您使用的参数化 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 结合使用时,@no__t 对象的顺序并不重要。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. 有关详细信息,请参阅脚本侵入概述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 窗体页的特性。A parameter that can be used to bind to an attribute of the current Web Forms page.
QueryStringParameter 一个参数,该参数可用于绑定到传递到查询字符串上的 Web 窗体页的值。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()

初始化该类供继承的类实例使用。Initializes the class for use by an inherited class instance. 此构造函数只能由继承的类调用。This constructor can be called only by an inherited class.

属性

Count

获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection.

(继承自 StateManagedCollection)
Item[Int32]

获取或设置集合中指定索引处的 Parameter 对象。Gets or sets the Parameter object at the specified index in the collection.

Item[String]

获取或设置集合中具有指定名称的 Parameter 对象。Gets or sets the Parameter object with the specified name in the collection.

方法

Add(Parameter)

将指定的 Parameter 对象追加到集合末尾。Appends the specified Parameter object to the end of the collection.

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)

用指定的名称和默认值创建 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)

用指定的名称、Parameter 和默认值创建 TypeCode 对象,并将它追加到集合末尾。Creates a Parameter object with the specified name, TypeCode, and default value, and appends it to the end of the collection.

Clear()

StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection.

(继承自 StateManagedCollection)
Contains(Parameter)

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

CopyTo(Array, Int32)

从特定的数组索引开始,将 StateManagedCollection 集合的元素复制到数组中。Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(继承自 StateManagedCollection)
CopyTo(Parameter[], Int32)

将指定的参数数组索引复制到参数集合中。Copies a specified index of a parameter array to the parameter collection.

CreateKnownType(Int32)

创建默认 Parameter 对象的实例。Creates an instance of a default Parameter object.

Equals(Object)

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

(继承自 Object)
GetEnumerator()

返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection.

(继承自 StateManagedCollection)
GetHashCode()

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

(继承自 Object)
GetKnownTypes()

获取 Parameter 集合可以包含的 ParameterCollection 类型的数组。Gets an array of Parameter types that the ParameterCollection collection can contain.

GetType()

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

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

获取集合当前包含的 Parameter 对象名称及其相应值的排序集合。Gets an ordered collection of Parameter object names and their corresponding values currently contained by the collection.

IndexOf(Parameter)

确定 Parameter 集合中的指定 ParameterCollection 对象的索引。Determines the index of a specified Parameter object in the ParameterCollection collection.

Insert(Int32, Parameter)

将指定的 Parameter 对象插入到 ParameterCollection 集合中的指定索引位置。Inserts the specified Parameter object into the ParameterCollection collection at the specified index.

MemberwiseClone()

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

(继承自 Object)
OnClear()

在派生类中替代时,在 Clear() 方法从集合中删除所有项之前执行附加工作。When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(继承自 StateManagedCollection)
OnClearComplete()

在清除此集合内容之后执行其他自定义进程。Performs additional custom processes after clearing the contents of the collection.

OnInsert(Int32, Object)

在调用 Insert(Int32, Parameter) 方法前发生。Occurs before the Insert(Int32, Parameter) method is called.

OnInsertComplete(Int32, Object)

Insert(Int32, Parameter) 方法完成后发生。Occurs after the Insert(Int32, Parameter) method completes.

OnParametersChanged(EventArgs)

引发 ParametersChanged 事件。Raises the ParametersChanged event.

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.

(继承自 StateManagedCollection)
OnRemoveComplete(Int32, Object)

Remove(Parameter) 方法完成后发生。Occurs after the Remove(Parameter) method completes.

OnValidate(Object)

当验证值时执行其他自定义进程。Performs additional custom processes when validating a value.

Remove(Parameter)

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

RemoveAt(Int32)

移除 Parameter 集合中指定索引处的 ParameterCollection 对象。Removes the Parameter object at the specified index from the ParameterCollection collection.

SetDirty()

强制将整个 StateManagedCollection 集合序列化为视图状态。Forces the entire StateManagedCollection collection to be serialized into view state.

(继承自 StateManagedCollection)
SetDirtyObject(Object)

将指定的 Parameter 对象标记为自上次从视图状态加载或保存后已发生更改。Marks the specified Parameter object as having changed since the last load or save from view state.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

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

遍历集合包含的 Parameter 对象,并对每个对象调用 Evaluate 方法。Iterates through the Parameter objects contained by the collection, and calls the Evaluate method on each one.

事件

ParametersChanged

当集合包含的一个或多个 Parameter 对象的状态改变时发生。Occurs when one or more Parameter objects contained by the collection changes state.

显式界面实现

ICollection.Count

获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection.

(继承自 StateManagedCollection)
ICollection.IsSynchronized

获取指示 StateManagedCollection 集合是否已同步(线程安全)的值。Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). 此方法在所有情况下均返回 falseThis method returns false in all cases.

(继承自 StateManagedCollection)
ICollection.SyncRoot

获取可用于同步对 StateManagedCollection 集合的访问的对象。Gets an object that can be used to synchronize access to the StateManagedCollection collection. 此方法在所有情况下均返回 nullThis method returns null in all cases.

(继承自 StateManagedCollection)
IEnumerable.GetEnumerator()

返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Add(Object)

StateManagedCollection 集合中添加一个项。Adds an item to the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Clear()

StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Contains(Object)

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

(继承自 StateManagedCollection)
IList.IndexOf(Object)

确定 StateManagedCollection 集合中的指定项的索引。Determines the index of a specified item in the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.Insert(Int32, Object)

将项在指定索引处插入 StateManagedCollection 集合中。Inserts an item into the StateManagedCollection collection at the specified index.

(继承自 StateManagedCollection)
IList.IsFixedSize

获取指示 StateManagedCollection 集合是否具有固定大小的值。Gets a value indicating whether the StateManagedCollection collection has a fixed size. 此方法在所有情况下均返回 falseThis method returns false in all cases.

(继承自 StateManagedCollection)
IList.IsReadOnly

获取指示 StateManagedCollection 集合是否为只读的值。Gets a value indicating whether the StateManagedCollection collection is read-only.

(继承自 StateManagedCollection)
IList.Item[Int32]

获取指定索引处的 IStateManager 元素。Gets the IStateManager element at the specified index.

(继承自 StateManagedCollection)
IList.Remove(Object)

StateManagedCollection 集合中删除指定对象的第一个匹配项。Removes the first occurrence of the specified object from the StateManagedCollection collection.

(继承自 StateManagedCollection)
IList.RemoveAt(Int32)

删除指定索引处的 IStateManager 元素。Removes the IStateManager element at the specified index.

(继承自 StateManagedCollection)
IStateManager.IsTrackingViewState

获取指示 StateManagedCollection 集合是否保存对其视图状态的更改的值。Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

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

还原 StateManagedCollection 集合以及其包含的 IStateManager 项的以前保存的视图状态。Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

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

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

(继承自 StateManagedCollection)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅