Data Source. Select Method
public: System::Collections::IEnumerable ^ Select();
public System.Collections.IEnumerable Select ();
member this.Select : unit -> System.Collections.IEnumerable
Public Function Select () As IEnumerable
An IEnumerable list of data rows.
For a code example, see ObjectDataSource.
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.
|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
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.
For more information about parameter merging, object lifetime, and method resolution, see SelectMethod.
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.