The requested page is not available for the requested platform. You are viewing the content for Default platform.

Register Predefined Data Sources

  • 3 min to read

This document describes how to provide data sources to the Web Report Designer. These data sources are available for all reports.

To do this, create the data sources at runtime and add them to the ASPxReportDesigner.DataSources collection.

using System;
using System.Web;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.Web;
// ...

public static void BindToData(ASPxReportDesigner reportDesigner) {
    // Create a SQL data source with the specified connection parameters.
    Access97ConnectionParameters connectionParameters =
        new Access97ConnectionParameters(HttpRuntime.AppDomainAppPath + "App_Data\\nwind.mdb", "", "");
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create a custom SQL query to access the Products data table.
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "Products";
    query.Sql = "SELECT * FROM Products";
    ds.Queries.Add(query);
    ds.RebuildResultSchema();

    // Create a JSON data source.
    JsonDataSource jsonDataSource = new JsonDataSource();

    // Specify the data source location.
    jsonDataSource.JsonSource = new UriJsonSource(new Uri("http://northwind.servicestack.net/customers.json"));

    // Retrieve data from the JSON data source to the Report Designer's Field List.
    jsonDataSource.Fill();

    // Add the created data sources to the list of predefined data sources. 
    reportDesigner.DataSources.Add("Northwind", ds);
    reportDesigner.DataSources.Add("JsonDataSource", jsonDataSource);
}
Note

The Json Data Source uses the open source Newtonsoft.Json library to provide JSON data at runtime. Install the Newtonsoft.Json package if your application does not reference this library.

When an end user adds one of the available data sources to a report, the data source object is cloned and its created copy is assigned to the XtraReportBase.DataSource property. This is required to properly serialize the data source settings along with the report layout data when the report is saved.

web-designer-field-list-add-data-source

For related code samples, please refer to the following online examples.

See Also