All docs
V21.2
21.2
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Object Data Source

  • 3 minutes to read

This tutorial shows how to add the DashboardObjectDataSource to data source storage and make it available to users.

  1. In your application, create the SalesPersonData class and add the following code:

    public class SalesPersonData {
    
        public string SalesPerson { get; set; }
        public int Quantity { get; set; }
    
        public static List<SalesPersonData> CreateData() {
            List<SalesPersonData> data = new List<SalesPersonData>();
            string[] salesPersons = { "Andrew Fuller", "Michael Suyama",
                                    "Robert King", "Nancy Davolio",
                                    "Margaret Peacock", "Laura Callahan",
                                    "Steven Buchanan", "Janet Leverling" };
            var rnd = new Random();
            for (int i = 0; i < 100; i++) {
                SalesPersonData record = new SalesPersonData();
                record.SalesPerson = salesPersons[rnd.Next(0, salesPersons.Length)];
                record.Quantity = rnd.Next(0, 100);
                data.Add(record);
            }
            return data;
        }
    }
    
  2. In the Default.aspx.cs (or .vb) file, create a public method that returns the configured dashboard’s data source storage (DataSourceInMemoryStorage) and define the Object data source.

    using System;
    using DevExpress.DashboardCommon;
    using DevExpress.DashboardWeb;
    
    public DataSourceInMemoryStorage CreateDataSourceStorage() {
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
    
        // Registers an Object data source.            
        DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
        dataSourceStorage.RegisterDataSource("objectDataSource", objDataSource.SaveToXml());  
    
        return dataSourceStorage;
    }
    
  3. Use the ASPxDashboard.DataLoading event to supply the dashboard with actual data at runtime.

    using DevExpress.DashboardWeb;
    using DevExpress.DataAccess.ObjectBinding;
    
    protected void Page_Load(object sender, EventArgs e) {
        // ...  
    
        ASPxDashboard1.DataLoading += DataLoading;
    }
    
    private void DataLoading(object sender, DataLoadingWebEventArgs e) {
        if(e.DataSourceName == "Object Data Source") {
            e.Data = SalesPersonData.CreateData();
        }
    }
    
  4. Call the ASPxDashboard.SetDataSourceStorage method to configure the data source storage. Use the created CreateDataSourceStorage method as the SetDataSourceStorage parameter.

    using DevExpress.DashboardWeb;
    
    protected void Page_Load(object sender, EventArgs e) {
        // ...  
    
        // Configures the data source storage.
        ASPxDashboard1.SetDataSourceStorage(CreateDataSourceStorage());
    }
    

The Object Data Source is now available in the Web Dashboard:

web-dashboard-ex-object-data-source

Users can now bind dashboard items to data in the Web Dashboard’s UI.

Example

The example shows how to make a set of data sources available for users in the Web Dashboard application.

View Example: How to Register Data Sources for ASP.NET Web Forms Dashboard Control