Retrieves data from the underlying data storage by calling the method that is identified by the ObjectDataSource.SelectMethod property with the parameters in the ObjectDataSource.SelectParameters collection.
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 System.Web.UI.WebControls.ObjectDataSource control to call it successfully.
IEnumerable |
The IEnumerable is returned by the ObjectDataSource.Select method. |
System.Data.DataTable |
A System.Data.DataView is created by using the System.Data.DataTable and returned by the ObjectDataSource.Select method. |
System.Data.DataView |
The System.Data.DataView is returned by the ObjectDataSource.Select method. |
System.Data.DataSet |
The first System.Data.DataTable of the System.Data.DataSet is extracted and a System.Data.DataView is created and returned by the ObjectDataSource.Select method. |
object |
The object is wrapped in a one-element IEnumerable collection and returned by the ObjectDataSource.Select method. |
The method that is identified by the ObjectDataSource.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 ObjectDataSource.SelectMethod property is called, except that the same instance is used to call the method that is specified by the ObjectDataSource.SelectMethod property and the method that is specified by the ObjectDataSource.SelectCountMethod property. The ObjectDataSource.Select method returns an IEnumerable interface. However, to enable caching and filtering scenarios, the return value must be a System.Data.DataSet object. While the System.Data.DataSet class does not implement the IEnumerable interface, the System.Web.UI.WebControls.ObjectDataSource control automatically extracts the default System.Data.DataView control, which implements the IEnumerable.
Before the ObjectDataSource.Select operation is performed, the ObjectDataSourceView.OnSelecting(ObjectDataSourceSelectingEventArgs) method is called to raise the ObjectDataSource.Selecting event. You can handle the ObjectDataSource.Selecting event to examine the values of the parameters and to perform any preprocessing before a ObjectDataSource.Select operation. To perform a data retrieval operation, the System.Web.UI.WebControls.ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the ObjectDataSource.TypeName property. It then calls the method that is identified by the ObjectDataSource.SelectMethod property, using any associated ObjectDataSource.SelectParameters properties. After the ObjectDataSource.Select operation completes, the ObjectDataSourceView.OnSelected(ObjectDataSourceStatusEventArgs) method is called to raise the ObjectDataSource.Selected event. You can handle the ObjectDataSource.Selected event to examine any return values, output parameters, and exceptions, and to perform any post-processing.
If the ObjectDataSource.SelectMethod property returns a System.Data.DataSet, System.Data.DataTable, or System.Data.DataView object and caching is enabled, the System.Web.UI.WebControls.ObjectDataSource retrieves data from and saves data to the cache during the ObjectDataSource.Select operation. The cache is created, discarded, or refreshed based on the caching behavior that is specified by the combination of the ObjectDataSource.CacheDuration and ObjectDataSource.CacheExpirationPolicy properties.
If the ObjectDataSource.SelectMethod property returns a System.Data.DataSet or System.Data.DataTable object, and a ObjectDataSource.FilterExpression property has been specified, it is evaluated with any supplied ObjectDataSource.FilterParameters properties and the resulting filter is applied to the list of data during the ObjectDataSource.Select operation.
The ObjectDataSource.Select method delegates to the erload:System.Web.UI.WebControls.ObjectDataSourceView.Select method of the System.Web.UI.WebControls.ObjectDataSourceView that is associated with the System.Web.UI.WebControls.ObjectDataSource control.
For more information about parameter merging, object lifetime, and method resolution, see ObjectDataSource.SelectMethod.
When the System.Web.UI.WebControls.ObjectDataSource control is associated with a data-bound control, such as the System.Web.UI.WebControls.GridView control, it is not necessary to call the ObjectDataSource.Select method from page code. The ObjectDataSource.Select method is invoked directly by the data-bound control instead.