1 out of 1 rated this helpful - Rate this topic

ParameterCollection Class

Represents a collection of Parameter and Parameter-derived objects that are used by data source controls in advanced data-binding scenarios.

System.Object
  System.Web.UI.StateManagedCollection
    System.Web.UI.WebControls.ParameterCollection

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public class ParameterCollection : StateManagedCollection

The ParameterCollection type exposes the following members.

  Name Description
Public method ParameterCollection Initializes the class for use by an inherited class instance. This constructor can be called only by an inherited class.
Top
  Name Description
Public property Count Gets the number of elements contained in the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Public property Item[Int32] Gets or sets the Parameter object at the specified index in the collection.
Public property Item[String] Gets or sets the Parameter object with the specified name in the collection.
Top
  Name Description
Public method Add(Parameter) Appends the specified Parameter object to the end of the collection.
Public method Add(String, String) Creates a Parameter object with the specified name and default value, and appends it to the end of the collection.
Public method 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.
Public method 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.
Public method Clear Removes all items from the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Public method Contains Determines whether the ParameterCollection collection contains a specific value
Public method CopyTo(Array, Int32) Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index. (Inherited from StateManagedCollection.)
Public method CopyTo(Parameter[], Int32) Copies a specified index of a parameter array to the parameter collection.
Protected method CreateKnownType Creates an instance of a default Parameter object. (Overrides StateManagedCollection.CreateKnownType(Int32).)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Returns an iterator that iterates through the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Protected method GetKnownTypes Gets an array of Parameter types that the ParameterCollection collection can contain. (Overrides StateManagedCollection.GetKnownTypes().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValues Gets an ordered collection of Parameter object names and their corresponding values currently contained by the collection.
Public method IndexOf Determines the index of a specified Parameter object in the ParameterCollection collection.
Public method Insert Inserts the specified Parameter object into the ParameterCollection collection at the specified index.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnClear When overridden in a derived class, performs additional work before the Clear method removes all items from the collection. (Inherited from StateManagedCollection.)
Protected method OnClearComplete Performs additional custom processes after clearing the contents of the collection. (Overrides StateManagedCollection.OnClearComplete().)
Protected method OnInsert Occurs before the Insert method is called. (Overrides StateManagedCollection.OnInsert(Int32, Object).)
Protected method OnInsertComplete Occurs after the Insert method completes. (Overrides StateManagedCollection.OnInsertComplete(Int32, Object).)
Protected method OnParametersChanged Raises the ParametersChanged event.
Protected method OnRemove When overridden in a derived class, performs additional work before the Remove(Object) or RemoveAt(Int32) method removes the specified item from the collection. (Inherited from StateManagedCollection.)
Protected method OnRemoveComplete Occurs after the Remove method completes. (Overrides StateManagedCollection.OnRemoveComplete(Int32, Object).)
Protected method OnValidate Performs additional custom processes when validating a value. (Overrides StateManagedCollection.OnValidate(Object).)
Public method Remove Removes the specified Parameter object from the ParameterCollection collection.
Public method RemoveAt Removes the Parameter object at the specified index from the ParameterCollection collection.
Public method SetDirty Forces the entire StateManagedCollection collection to be serialized into view state. (Inherited from StateManagedCollection.)
Protected method SetDirtyObject Marks the specified Parameter object as having changed since the last load or save from view state. (Overrides StateManagedCollection.SetDirtyObject(Object).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method UpdateValues Iterates through the Parameter objects contained by the collection, and calls the Evaluate method on each one.
Top
  Name Description
Public event ParametersChanged Occurs when one or more Parameter objects contained by the collection changes state.
Top
  Name Description
Explicit interface implemetation Private property ICollection.Count Infrastructure. Gets the number of elements contained in the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property ICollection.IsSynchronized Infrastructure. Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). This method returns false in all cases. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property ICollection.SyncRoot Infrastructure. Gets an object that can be used to synchronize access to the StateManagedCollection collection. This method returns null in all cases. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IEnumerable.GetEnumerator Infrastructure. Returns an iterator that iterates through the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.Add Adds an item to the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.Clear Infrastructure. Removes all items from the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.Contains Determines whether the StateManagedCollection collection contains a specific value. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.IndexOf Determines the index of a specified item in the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.Insert Inserts an item into the StateManagedCollection collection at the specified index. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property IList.IsFixedSize Infrastructure. Gets a value indicating whether the StateManagedCollection collection has a fixed size. This method returns false in all cases. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property IList.IsReadOnly Infrastructure. Gets a value indicating whether the StateManagedCollection collection is read-only. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property IList.Item Infrastructure. Gets the IStateManager element at the specified index. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.Remove Removes the first occurrence of the specified object from the StateManagedCollection collection. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IList.RemoveAt Removes the IStateManager element at the specified index. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private property IStateManager.IsTrackingViewState Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method IStateManager.LoadViewState Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains. (Inherited from StateManagedCollection.)
Explicit interface implemetation Private method 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.)
Explicit interface implemetation Private method 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.)
Top

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.

Security note Security Note

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.

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.

Security note Security Note

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>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ