Parameter Class
Updated: July 2009
Provides a mechanism that data source controls use to bind to application variables, user identities and choices, and other data. Serves as the base class for all ASP.NET parameter types.
Assembly: System.Web (in System.Web.dll)
The Parameter class represents a parameter in a parameterized SQL query, a filtering expression, or a business object method call that an ASP.NET data source control uses to select, filter, or modify data. Parameter objects are contained in a ParameterCollection object. Parameter objects are evaluated at run time, to bind the values of the variables they represent to whatever method is used by a data source control to interact with data.
Use classes that derive from Parameter with data source and data-bound controls to build Web-based data applications. These parameter classes are used by data source controls to bind specific kinds of values found in Web applications to placeholders in SQL query strings, business object method parameters, and more. The following table lists parameter types that are included in ASP.NET.
Binds any public property of a Web server control. | |
Binds a form field. | |
Binds a session-state field. | |
Binds a cookie field. | |
Binds a query-string parameter. | |
Binds a profile field. |
Extend the base Parameter class when you want to implement your own custom parameter types.
Parameter objects are very simple: they have a Name and a Type property, can be represented declaratively, and can track state across multiple HTTP requests. All parameters support a DefaultValue property, for cases when a parameter is bound to a value, but the value evaluates to nullptr at run time.
When using a collection of Parameter objects with a data source control, their order in the collection might matter. For more information on how parameters are used, see Using Parameters with the SqlDataSource Control and Using Parameters with the ObjectDataSource Control.
The following example shows how to use the selected value of a DropDownList control in the Where clause of a SQL query. The example uses the ControlParameter class, which derives from the ControlParameter class.
The SelectCommand element defines the query with a parameter named "@Title" where the value from DropDownList1 should go. The ControlParameter element specifies that the "@Title" placeholder will be replaced by the value of the SelectedValue property of the DropDownList1 control. The ControlParameter element is added to the SelectParameters collection of the SqlDataSource control.
The following example is like the previous one, but uses code instead of markup. When the page loads the first time, the DropDownList control has no selected value, and the DefaultValue property of the Parameter object is used.
The following code shows the code-behind class for the page in the previous example.
The following code example demonstrates how to extend the Parameter class to create a new parameter type that can be used by data source controls and other controls in data-binding scenarios. A data source control can use a StaticParameter parameter to bind to the value of any object, typically a string, declared on a Web Forms page.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.WebControls::Parameter
System.Web.UI.WebControls::ControlParameter
System.Web.UI.WebControls::CookieParameter
System.Web.UI.WebControls::FormParameter
System.Web.UI.WebControls::ProfileParameter
System.Web.UI.WebControls::QueryStringParameter
System.Web.UI.WebControls::SessionParameter
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.