ObjectDataSource.Select ObjectDataSource.Select ObjectDataSource.Select ObjectDataSource.Select Method


通过用 SelectMethod 集合中的参数调用由 SelectParameters 属性标识的方法,从基础数据存储中检索数据。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.

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


一个数据行的 IEnumerable 列表。An IEnumerable list of data rows.


有关代码示例,请参见 ObjectDataSourceFor a code example, see ObjectDataSource.


指定的方法可能具有任何方法签名, 但它必须返回或派生自下表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.

返回类型Return type 操作Action
IEnumerable IEnumerableSelect方法返回。The IEnumerable is returned by the Select method.
DataTable 是使用方法创建Select的, 并由方法返回。 DataTable DataViewA DataView is created by using the DataTable and returned by the Select method.
DataView DataViewSelect方法返回。The DataView is returned by the Select method.
DataSet DataTable DataView Select第一个提取, 并由方法创建并返回。 DataSetThe first DataTable of the DataSet is extracted and a DataView is created and returned by the Select method.
Object 对象包装在一个单元素IEnumerable集合中, 并Select由方法返回。The object is wrapped in a one-element IEnumerable collection and returned by the Select method.

SelectMethod属性标识的方法可以是实例方法, static也可以是 (Shared在 Visual Basic) 方法。The method that is identified by the SelectMethod property can be an instance method or a static (Shared in Visual Basic) method. 如果它是实例方法, 则每次调用SelectMethod属性指定的方法时都会创建并销毁业务对象, 只不过相同的实例用于调用SelectMethod由属性指定的方法和由SelectCountMethod属性指定的方法。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. Select 方法IEnumerable返回接口。The Select method returns an IEnumerable interface. 但是, 若要启用缓存和筛选方案, 返回值必须为DataSet对象。However, to enable caching and filtering scenarios, the return value must be a DataSet object. IEnumerable ObjectDataSource DataView虽然类不实现接口, 但控件会自动提取实现的IEnumerable默认控件。 DataSetWhile the DataSet class does not implement the IEnumerable interface, the ObjectDataSource control automatically extracts the default DataView control, which implements the IEnumerable.

在执行OnSelecting操作之前, 将调用方法来引发Selecting事件。 SelectBefore the Select operation is performed, the OnSelecting method is called to raise the Selecting event. 您可以处理Selecting事件以检查参数的值并在Select操作之前执行任何预处理。You can handle the Selecting event to examine the values of the parameters and to perform any preprocessing before a Select operation. 若要执行数据检索操作, ObjectDataSourceView对象使用反射来创建TypeName由属性标识的对象的实例。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. 然后, 它使用任意关联SelectMethod SelectParameters的属性调用由属性标识的方法。It then calls the method that is identified by the SelectMethod property, using any associated SelectParameters properties. 操作完成后OnSelected , 调用方法来引发Selected事件。 SelectAfter the Select operation completes, the OnSelected method is called to raise the Selected event. 您可以处理Selected事件以检查任何返回值、输出参数和异常, 并执行任何后续处理。You can handle the Selected event to examine any return values, output parameters, and exceptions, and to perform any post-processing.

ObjectDataSource Select如果属性返回DataSetDataTableDataView对象并启用了缓存, 则在操作过程中, 将从中检索数据并将数据保存到缓存中。 SelectMethodIf 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. 根据CacheDurationCacheExpirationPolicy属性的组合指定的缓存行为, 创建、放弃或刷新缓存。The cache is created, discarded, or refreshed based on the caching behavior that is specified by the combination of the CacheDuration and CacheExpirationPolicy properties.

FilterParameters如果属性返回或对象并指定了属性, 则使用任何提供的属性对其进行计算, 并将生成的筛选器应用于FilterExpression DataSet SelectMethod DataTableSelect操作。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.

方法委托ObjectDataSourceView Select给与ObjectDataSource控件关联的的方法。 SelectThe Select method delegates to the Select method of the ObjectDataSourceView that is associated with the ObjectDataSource control.

有关参数合并、对象生存期和方法解析的详细信息, 请参阅SelectMethodFor more information about parameter merging, object lifetime, and method resolution, see SelectMethod.

数据绑定控件Data-Bound Controls

当控件与数据绑定控件 (如GridView控件) 关联时, Select无需从页代码中调用方法。 ObjectDataSourceWhen 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. 改为直接通过数据绑定控件调用方法。SelectThe Select method is invoked directly by the data-bound control instead.