This documentation is archived and is not being maintained.

ObjectDataSource.SelectParameters Property

Updated: April 2009

Gets a collection of parameters that are used by the method that is specified by the SelectMethod property.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public ParameterCollection SelectParameters { get; }

Property Value

Type: System.Web.UI.WebControls.ParameterCollection
A collection of parameters that are used by the method specified by the SelectMethod property.

The SelectParameters property gets the SelectParameters property of the ObjectDataSourceView object that is associated with the ObjectDataSource control.

You add parameters to the SelectParameters collection declaratively by using the SelectParameters element or programmatically in the handler for the Selecting event. At run time, parameters listed in the SelectParameters element are added to the collection first. Parameters in the collection are then added or removed by the handler for the Selecting event. The Selecting event is raised before the Select method is run.

Before the Select method is run, the names and types of the parameters that are contained in the SelectParameters collection must match the signature of the method that is specified by the SelectMethod property. For example, if a select method named GetEmployeesByStateAndAge takes a string and an integer as parameters, the SelectParameters collection must contain two parameters. The first parameter must resolve to a string and the second parameter must resolve to an integer. Both parameters can be specified in markup in the SelectParameters element. Alternatively, they can be can be added in the Selecting event handler, or one parameter can be added in markup and the other one can be added programmatically.

For more information, see Using Parameters with the ObjectDataSource Control and the SelectMethod property.

Security noteSecurity Note:

In the code for the Selecting event handler or in the method that is specified by the SelectMethod property, make sure that you validate any parameter value that is received from the client.

The following code example demonstrates how to retrieve a single data record using an ObjectDataSource control and display it in a DetailsView control. The ObjectDataSource control retrieves a specific employee record by calling the GetEmployee method of the EmployeeLogic class. The GetEmployee method requires an employee ID parameter. The ObjectDataSource control uses a QueryStringParameter element in markup to create a QueryStringParameter object that will retrieve the value of a specified query-string parameter from the URL and pass it to the GetEmployee method.

Other parameter classes can be used to retrieve values from other sources, such as control properties, form fields, cookies, ASP.NET profile data, or session state. You can also use a parameter object that is defined in markup in order to pass a hard-coded value to the select method. For more information about parameter classes that are available, see Using Parameters with Data Source Controls.

To run this example, you will need the following:

  • A Web site that has a connection string named NorthwindConnection that connects to the Northwind Traders database. For more information, see the ObjectDataSource class overview.

  • The EmployeeLogic class that is shown as one of the code examples for the ObjectDataSource class overview. The class file must be located in the App_Code folder.

  • The sample code can be run as an .aspx page. If you request the page without a query-string parameter, an error message is displayed. If you request the page using a query string such as ?empid=1 after the name of the .aspx file, you will see the details for the requested employee.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
    <title>ObjectDataSource - C# Example</title>
    <form id="Form1" method="post" runat="server">


<!-- Security Note: The ObjectDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->

          typename="Samples.AspNet.CS.EmployeeLogic" >
            <asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />


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.

.NET Framework

Supported in: 3.5, 3.0, 2.0




April 2009

Rewrote Remarks section and Code Example introduction to make them easier to understand.

Customer feedback.