Articles in this section
Category / Section

How to load SubReport in Syncfusion ASP.NET Core Report Viewer

2 mins read

Syncfusion ASP.NET Core ReportViewer allows you to render reports, which are embedded with one another using the subreport report item. The following steps help you to load the RDLC report with subreport item in a Report Viewer:

1. Create a simple ReportViewer application with the help of getting started documentation.

2. Right-click the project and go to the Add New Item dialog. In the dialog, select Report Wizard and name it as MainReport.rdlc for the report, and then click Add.

3. Repeat the step_2 to add the subreport and name it SubReport.rdlc.

4. Right-click the subreport, and then click Subreport Properties.

5. As per RDL standards, you can set the SubReport Path and properties like Microsoft ReportViewer as follows. In the Subreport Properties dialog box, type a name in the Name text box. The name must be unique within the report.

Subreport Properties dialog box

6. You can pass the data source values to the OnReportLoaded method of subreport as shown in the following example.

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            string basePath = _hostingEnvironment.WebRootPath;
 
            if (reportOption.SubReportModel != null)
            {
                FileStream SubStream = new FileStream(basePath + @"\ReportData\SubReport.rdlc", FileMode.Open, FileAccess.Read);
                reportOption.SubReportModel.Stream = SubStream;
            }
            else
            {
                FileStream inputStream = new FileStream(basePath + @"\ReportData\MainReport.rdlc", FileMode.Open, FileAccess.Read);
                reportOption.ReportModel.Stream = inputStream;
            }
        }
 
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
            if (reportOption.SubReportModel != null)
            {
                reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData() });
            }
            else
            {
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "TopSalesPerson", Value = SalesPersons.GetTopSalesPerson() });
            }
        }

List of supported properties of subreport

The ReportViewer has the following subreport properties to set the DataSources, Parameters, and more through code behind.

DataSources

Gets/sets the data sources of the subreport.

DataSourceName

Gets the data sources names of the subreport.

Parameters

Gets/sets the parameters to the subreport.

ReportPath

Gets/sets the report path of the subreport.

Stream

Sets the report stream to the subreport.

 

Run the application

Run the sample application. You can see the RDLC subreport loaded in the ReportViewer as shown in the following screenshot.

       Report Viewer

Download the sample application with subreport from here.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied