ObjectDataSource.SelectParameters Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

member SelectParameters : ParameterCollection with 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.

System_CAPS_security Security 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 for Filtering.

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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top