ObjectDataSource Control Overview

The ASP.NET ObjectDataSource control represents a middle-tier object with data retrieval and update capabilities. The ObjectDataSource control acts as a data interface for data-bound controls such as the GridView, FormView, or DetailsView controls, and enables those controls to display and edit data from a middle-tier business object on an ASP.NET Web page.

Most ASP.NET data source controls, such as the SqlDataSource, are used in a two-tier application architecture where the presentation layer (the ASP.NET Web page) communicates directly with the data tier (the database, an XML file, and so on). However, a common application design practice is to separate the presentation layer from business logic and encapsulate the business logic in business objects. These business objects form a layer between the presentation layer and the data tier, resulting in a three-tier application architecture. The ObjectDataSource control supports a three-tier architecture by providing a way for you to bind data controls on the page to a middle-tier business object. The ObjectDataSource works with a middle-tier business object to select, insert, update, delete, page, sort, cache, and filter data declaratively without extensive code.

The ObjectDataSource control uses reflection to call methods of a business object to select, update, insert, and delete data. You set the ObjectDataSource control's TypeName property to specify the name of the class to use as a source object. For details on how to create a source data object to be used with the ObjectDataSource control, see Creating an ObjectDataSource Control Source Object.

The ObjectDataSource control can support additional sorting and paging capabilities by passing sort and page information in requests from a data-bound control, such as a GridView control, to the data object for processing. The source data object or the data source control itself can then sort data and return data in pages.

For information on passing sorting and paging parameters to an ObjectDataSource control's data object, see Using Parameters with the ObjectDataSource Control.

The ObjectDataSource control can cache objects returned by the underlying business object. However, you should not cache objects that hold resources or that maintain state that cannot be shared among multiple requests, such as an open DataReader object.

If the object returned to the ObjectDataSource control by the source data object is a DataSet or DataTable object, the ObjectDataSource control supports filtering using the syntax of the Expression property of the DataColumn class. Filtering enables you to expose only rows that match particular search criteria, without having to re-query the data source with new selection criteria. For more information, see Filtering Data Using Data Source Controls.

By setting the ObjectDataSource control's ConflictDetection property to true, you can specify that the ObjectDataSource control should include original values when calling update methods of the source data object. The original values can then be included in checks for optimistic concurrency. For more information, see Using Parameters with the ObjectDataSource Control. For information on optimistic concurrency checking, see Using Optimistic Concurrency.

Community Additions