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.
Any of the following data sources can be assigned to the DataSource property of the ObjectDataSource component:
Any component that implements IDataAdapter, including SqlDataAdapter and OleDbDataAdapter
System.Type which represents the type of the business object
DataSourcereference contains more than one table, you must set the
DataMemberproperty 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
OrderDetails, 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 the
- If the
DataSourcereferences a strongly typed array of objects (business objects) these objects must contain public properties.
- If the
DataSourceis a business object, the
DataMemberproperty specifies the name of the method that should be invoked to retrieve the data.
- If the
DataMemberproperty 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
Parameterscollection of the
- You can also bind to an
ArrayList. A feature of the
ArrayListis that it can contain objects of multiple types. The
ObjectDataSourcecomponent 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.
- .NET Framework 4.0 and above
- .NET Core 2.0 and above
- .NET 5 and above
- .NET Standard 2.0 and above