ParameterCollection ParameterCollection ParameterCollection ParameterCollection Class

Definition

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
Inheritance
ParameterCollectionParameterCollectionParameterCollectionParameterCollection

Examples

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. The FormParameter object is added to the SelectParameters collection using the Add method.

Important

This example has a text box that accepts user input, which is a potential security threat. 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>

Remarks

The ParameterCollection class represents a collection of Parameter objects used in advanced data-binding scenarios with data source controls. 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.

Use the ParameterCollection class to programmatically manage a set of Parameter objects. You can add, insert, and remove Parameter objects using the appropriate methods of the ParameterCollection class. To programmatically retrieve Parameter objects from a collection, use one of following methods:

The Count property specifies the total number of items in the collection, and is used to determine the upper bound of the collection. You can add and remove items from the collection by using the Add, Insert, Remove, and RemoveAt methods.

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. 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. However, when using the SqlDataSource control with Microsoft SQL Server, the order of the Parameter objects are not important.

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. 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 A parameter that can be used to bind to the value of a cookie.
FormParameter A parameter that can be used to bind to an attribute of the current Web Forms page.
QueryStringParameter 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 A parameter that can be used to bind to the value of an ASP.NET Profile property.

Constructors

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

Initializes the class for use by an inherited class instance. This constructor can be called only by an inherited class.

Properties

Count Count Count Count

Gets the number of elements contained in the StateManagedCollection collection.

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

Gets the number of elements contained in the StateManagedCollection collection.

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

Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). This method returns false in all cases.

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

Gets an object that can be used to synchronize access to the StateManagedCollection collection. This method returns null in all cases.

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

Gets a value indicating whether the StateManagedCollection collection has a fixed size. This method returns false in all cases.

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

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]

Gets the IStateManager element at the specified index.

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

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]

Gets or sets the Parameter object at the specified index in the collection.

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

Gets or sets the Parameter object with the specified name in the collection.

Methods

Add(Parameter) Add(Parameter) Add(Parameter) Add(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)

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)

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)

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()

Removes all items from the StateManagedCollection collection.

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

Determines whether the ParameterCollection collection contains a specific value.

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

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)

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()

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()

Gets an array of Parameter types that the ParameterCollection collection can contain.

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

Gets the Type of the current instance.

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

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)

Determines the index of a specified Parameter object in the ParameterCollection collection.

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

Inserts the specified Parameter object into the ParameterCollection collection at the specified index.

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

Creates a shallow copy of the current Object.

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

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)

Occurs before the Insert(Int32, Parameter) method is called.

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

Occurs after the Insert(Int32, Parameter) method completes.

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

Raises the ParametersChanged event.

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

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)

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)

Removes the specified Parameter object from the ParameterCollection collection.

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

Removes the Parameter object at the specified index from the ParameterCollection collection.

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

Forces the entire StateManagedCollection collection to be serialized into view state.

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

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)

Iterates through the Parameter objects contained by the collection, and calls the Evaluate method on each one.

Events

ParametersChanged ParametersChanged ParametersChanged ParametersChanged

Occurs when one or more Parameter objects contained by the collection changes state.

Explicit Interface Implementations

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

Returns an iterator that iterates through the StateManagedCollection collection.

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

Adds an item to the StateManagedCollection collection.

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

Removes all items from the StateManagedCollection collection.

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

Determines whether the StateManagedCollection collection contains a specific value.

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

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)

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)

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)

Removes the IStateManager element at the specified index.

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

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()

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()

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)

Extension Methods

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

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(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)

Converts an IEnumerable to an IQueryable.

Applies to

See also