Rediger

Del via


ObjectDataSource.Select Method

Definition

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.

public:
 System::Collections::IEnumerable ^ Select();
public System.Collections.IEnumerable Select ();
member this.Select : unit -> System.Collections.IEnumerable
Public Function Select () As IEnumerable

Returns

An IEnumerable list of data rows.

Examples

For a code example, see ObjectDataSource.

Remarks

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.

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.

Applies to

See also