Skip to main content

ObjectDataSource Class

Enables binding data-aware controls and components to a runtime-created object or an instance method.

Namespace: DevExpress.DataAccess.ObjectBinding

Assembly: DevExpress.DataAccess.v22.2.dll

NuGet Package: DevExpress.DataAccess


[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.ObjectDataSource.bmp")]
[ToolboxSvgImage("DevExpress.DataAccess.Images.ObjectDataSource.svg,DevExpress.DataAccess.v22.2, Version=, Culture=neutral, PublicKeyToken=c38a27d2243c2672")]
[XRDesigner("DevExpress.DataAccess.UI.Design.XRObjectDataSourceDesigner,DevExpress.DataAccess.v22.2.UI, Version=, Culture=neutral, PublicKeyToken=c38a27d2243c2672", typeof(IDesigner))]
public class ObjectDataSource :


ObjectDataSource can be used to supply the following controls/components with data.

Use the ObjectDataSource when your data is provided by an object or there is a method that returns the data as an object, and it is not required to connect to a database to obtain the data.

When such an object cannot be accessed from your application code, you can use the ObjectDataSource to obtain the data. For example, it is possible to launch the Data Source wizard at runtime and use it to select a required assembly (from among those referenced in the project), and within it, a specific type and method without rebuilding your project and writing any code.

An ObjectDataSource can be bound to a public class or public member (property or method) of a public class that returns an object implementing the IEnumerable<T> interface. This member can either be a static, or instance property (method).

The following properties are used to bind the ObjectDataSource to data.

  • ObjectDataSource.DataSource

    It can be assigned a specific object instance or a type.

    Because the Data Source wizard cannot be used for binding to a specific object instance, it is required to assign this instance to the DataSource property in code before calling the ObjectDataSource.Fill method. In the wizard, this scenario corresponds to the “Retrieve the data source schema” option.

    If the DataSource property has been assigned a type, the ObjectDataSource will try to create an instance of this type when calling the ObjectDataSource.Fill method (this will require specifying the constructor parameters, which is explained further in this article). In the wizard, this scenario corresponds to the “Retrieve the actual data” option.


    If the ObjectDataSource.DataMember property (see below) has been assigned a static member, creating an instance of the corresponding type is not required, nor is specifying the constructor parameters.

  • ObjectDataSource.DataMember

    To bind the ObjectDataSource to an object, leave this property set to null. In the wizard, this scenario corresponds to the following option: “Do not select a member, bind to the entire object”.

    To bind the ObjectDataSource to a property or method, assign its name to the DataMember property. When binding to a method, it is also required to specify this method’s parameters (as described further in this article).

  • ObjectDataSource.Parameters

    To bind to a method, this collection must contain parameters that are required to call this method and obtain the data. In any other case, leave this collection empty.

  • ObjectDataSource.RebuildResultSchema
    Call this method to build the data source schema.
    Call the RebuildResultSchema(IEnumerable<IParameter>) overloaded method instead to apply values from external parameters (for instance, report parameters) to the data source parameters before the schema is built.

  • ObjectDataSource.Constructor

    If it is required that on calling the ObjectDataSource.Fill method, an ObjectDataSource should create an instance of the type specified by its ObjectDataSource.DataSource property, use the Constructor property to specify the required constructor parameters. To assign a constructor without parameters, use the static ObjectConstructorInfo.Default object.

    View Example: How to Create a Report Bound to the ObjectDataSource with Constructor Parameters Linked to Report Parameters

    Set this property to null for the ObjectDataSource to never try to create an object instance (if you need to manually create and assign it, or when binding to a static member).

To make a specific assembly, class or member appear in the Data Source wizard, use the following attributes: HighlightedAssemblyAttribute, HighlightedClassAttribute and HighlightedMemberAttribute.


See Also