Export (0) Print
Expand All

ObjectDataSource.Select Method

Retrieves data from the underlying data storage by calling the method that is identified by the SelectMethod property with the parameters in the SelectParameters collection.

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

public IEnumerable Select ()
public IEnumerable Select ()
public function Select () : IEnumerable
Not applicable.

Return Value

An IEnumerable list of data rows.

The specified method might have any method signature, but it must return or be derived from one of the types listed in the following table for the ObjectDataSource control to call it successfully.

NoteNote:

If you are not familiar with the Data Access features in ASP.NET 2.0, you should read some of these topics before continuing:

Return type

Action

IEnumerable

The IEnumerable is returned by the Select method.

DataTable

A DataView is created by using the DataTable and returned by the Select method.

DataView

The DataView is returned by the Select method.

DataSet

The first DataTable of the DataSet is extracted and a DataView is created and returned by the Select method.

Object

The object is wrapped in a one-element IEnumerable collection and returned by the Select method.

The method that is identified by the SelectMethod property can be an instance method or a static (Shared in Visual Basic) method. If it is an instance method, the business object is created and destroyed each time the method that is specified by the SelectMethod property is called, except that the same instance is used to call the method that is specified by the SelectMethod property and the method that is specified by the SelectCountMethod property. The Select method returns an IEnumerable interface. However, to enable caching and filtering scenarios, the return value must be a DataSet object. While the DataSet class does not implement the IEnumerable interface, the ObjectDataSource control automatically extracts the default DataView control, which implements the IEnumerable.

Before the Select operation is performed, the OnSelecting method is called to raise the Selecting event. You can handle the Selecting event to examine the values of the parameters and to perform any preprocessing before a Select operation. To perform a data retrieval operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. It then calls the method that is identified by the SelectMethod property, using any associated SelectParameters properties. After the Select operation completes, the OnSelected method is called to raise the Selected event. You can handle the Selected event to examine any return values, output parameters, and exceptions, and to perform any post-processing.

If the SelectMethod property returns a DataSet, DataTable, or DataView object and caching is enabled, the ObjectDataSource retrieves data from and saves data to the cache during the Select operation. The cache is created, discarded, or refreshed based on the caching behavior that is specified by the combination of the CacheDuration and CacheExpirationPolicy properties.

If the SelectMethod property returns a DataSet or DataTable object, and a FilterExpression property has been specified, it is evaluated with any supplied FilterParameters properties and the resulting filter is applied to the list of data during the Select operation.

The Select method delegates to the Select method of the ObjectDataSourceView that is associated with the ObjectDataSource control.

For more information about parameter merging, object lifetime, and method resolution, see SelectMethod.

Data-Bound Controls

When the ObjectDataSource control is associated with a data-bound control, such as the GridView control, it is not necessary to call the Select method from page code. The Select method is invoked directly by the data-bound control instead.

For a code example, see ObjectDataSource.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft