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

Register Predefined Data Sources

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

  1. Add a new Report Designer Model (for instance, the ReportDesignerModel file) to the Models folder and insert the following code:

    using DevExpress.XtraReports.UI;
    
    namespace WebApplication1.Models {
        public class ReportDesignerModel {
            public XtraReport Report { get; set; }
            public Dictionary<string, object> DataSources { get; set; }
        }
    }
    
  2. Open the Controller file and initialize model data. Create a new SqlDataSource class instance and use the SelectQueryFluentBuilder class to construct a SELECT statement.

    using Microsoft.AspNetCore.Mvc;
    using DevExpress.DataAccess.Sql;
    using DevExpress.DataAccess.ConnectionParameters;
    using DevExpress.XtraReports.UI;
    using WebApplication1.Models;
    
    // ...
    public class HomeController : Controller {
        public IActionResult Index() {
            MsSqlConnectionParameters parameters = new MsSqlConnectionParameters("localhost",
                "dbName", "userName", "password", MsSqlAuthorizationType.SqlServer);
            SqlDataSource dataSource = new SqlDataSource(parameters);
            SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products");
            dataSource.Queries.Add(query);
            dataSource.RebuildResultSchema();
            var model = new ReportDesignerModel
            {
                // Open your report here.
                Report = new XtraReport()
            };
            model.DataSources.Add("Northwind", dataSource);
            return View(model);
        }
        // ...
    }
    
  3. In the View file, modify your code to obtain data sources from the model and add them to the Report Designer's DataSources collection.

    @model ReportDesignerModel
    
    @Html.DevExpress().ReportDesigner("ReportDesigner")
        .Height("1000px")
        .Bind(Model.Report)
        .DataSources(configureDS => { foreach (var ds in Model.DataSources) { configureDS.Add(ds.Key, ds.Value); } });
    

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

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