Register Predefined Data Sources

  • 2 minutes 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 and add them to the ReportDesignerSettings.DataSources collection.

@using DevExpress.DataAccess.ConnectionParameters
@using DevExpress.DataAccess.Sql
@using DevExpress.DataAccess.Json

@Html.DevExpress().ReportDesigner(settings => {
    settings.Name = "ReportDesigner";

    // Create a SQL data source with specified connection parameters.
    MsSqlConnectionParameters connectionParameters =
            new MsSqlConnectionParameters("localhost", "Northwind", null, null, MsSqlAuthorizationType.Windows);
    DevExpress.DataAccess.Sql.SqlDataSource ds = new DevExpress.DataAccess.Sql.SqlDataSource(connectionParameters);

    // Create a SelectQuery to access all columns of the Products data table.
    SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumns().Build("Products");

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

    // Specify the data source location.
    jsonDataSource.JsonSource = new UriJsonSource(new Uri(""));

    // Retrieve data from the JSON data source to the Report Designer's Field List.

    // Add the created data sources to the list of default data sources. 
    settings.DataSources.Add("Northwind", ds);
    settings.DataSources.Add("JsonDataSource", jsonDataSource);
}).Bind(new XtraReport()).GetHtml()

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.


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

See Also