ObjectDataSource Component Overview
A common application design practice is to separate the presentation layer from the 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 multi-tier application architecture. The ObjectDataSource component supports the multi-tier architecture by providing a way for you to bind the Data Report Items to a middle-tier business object without extensive code. The ObjectDataSource component represents the middle-tier object (business object or any other class) and provides data retrieval capabilities.
Supported object types
Any of the following data sources can be assigned to the DataSource property of the ObjectDataSource component:
Any component that implements IEnumerable, including System.Array, IList, ICollection, and BindingSource
Any component that implements IListSource, including DataTable, DataSet and DataView
Any component that implements IDataAdapter, including SqlDataAdapter and OleDbDataAdapter
Any component that implements ITypedList, including DataView and DataViewManager
System.Type which represents the type of the business object
Requirements for the DataSource
-
If the
DataSource
reference contains more than one table, you must set theDataMember
property to a string that specifies the table to bind to.For example, if the DataSource is a DataSet or DataViewManager that contains three tables named
Customers
,Orders
, andOrderDetails
, you need to specify the table to bind to. If the name of the
DataMember
(i.e. the table to bind to) is not specified, the first Table of the DataSet will be bound to theDataSource
.- If the
DataSource
references a strongly typed array of objects (business objects) these objects must contain public properties. - If the
DataSource
is a business object, theDataMember
property specifies the name of the method that should be invoked to retrieve the data. - If the
DataMember
property is not specified, the constructor of the type will be invoked. - If the constructor or the method contains arguments they can be specified through the
Parameters
collection of theObjectDataSource
component. - You can also bind to an
ArrayList
. A feature of theArrayList
is that it can contain objects of multiple types. TheObjectDataSource
component binds to such a list despite the types of items in it. The only requirement is that they provide public properties with the same names as they are used in the expressions. - Already instantiated data objects do not have to be wrapped in a data source component. Instantiated data objects can be set directly to data items' DataSource properties.
Supported developer platforms
- .NET Framework 4.6.2 and above
- .NET 6 and above
- .NET Standard 2.0 and above