Articles in this section
Category / Section

How to Load SubReport in ASP.NET MVC Report Viewer?

3 mins read

Syncfusion ASP.NET MVC 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.

Provide unique subreport name

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

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 source of the subreport.

DataSourceName

Gets the data source 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 report loaded in the ReportViewer as shown in the following screenshot.

       RDLC report generated in ReportViewer

Download the sample application with subreport from here.


Conclusion

I hope you enjoyed learning how to load subreport in ASP.NET MVC ReportViewer.

You can refer to the ASP.NET MVC ReportViewer feature tour page to learn about its other groundbreaking feature representations and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC ReportViewer example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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