We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

Subreports

Hello,

I have a subreport currently in a main report that does fact display. However, the subreport is not receiving any data. All datasets are defined, both the main report and subreport use the same datasource. How do I pass the data to the subreport, to be shown when the main report appears?

The main report and the subreport renders currently. But the subreport does not display any data.

I am using a controller to populate the data using ViewData and the html file looks like this:

@Html.EJ().ReportViewer("reportviewer").ProcessingMode(Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Local).ReportPath("~/Views/Reports/ReportMain.rdlc").ReportServiceUrl(VirtualPathUtility.ToAbsolute("~/api/ReportsApi")).ReportLoaded("onReportLoaded").DataSources(ds => { ds.Name("DataSet1").Value(ViewData["ReportData"]).Add(); ds.Name("DataSet2").Value(ViewData["ReportData2"]).Add(); })

The rdlc file called is the main report that contains the subreport.



3 Replies

SR Soundara Rajan S Syncfusion Team October 1, 2015 07:24 AM UTC

Hi Hemraj,

Thanks for contacting Syncfusion support.

We have already exposed the SubReportModel property in WebAPI(IReportController) side. By using this, you can pass the DataSource values to Sub Report on Report Loaded method as shown in the below example,

        Public void OnReportLoaded(ReportViewerOptions reportOption)

        {

            if (reportOption.SubReportModel != null)

            {

                DataSourceValus val = new DataSourceValus();

                reportOption.SubReportModel.DataSources.Add(new ReportDataSource()

                {

                    Name = "DataSet1",

                    Value = val.GetDataSource()

                });

            }

            else

            {

                DataSourceValus val = new DataSourceValus();

                reportOption.ReportModel.DataSources.Add(new ReportDataSource()

                {

                    Name = "DataSet1",

                    Value = val.GetDataSource1()

                });

            }

        }


We have prepared a sample and it can be downloaded from the below location,
http://www.syncfusion.com/downloads/support/forum/120653/ze/SubReportDemo15842735.zip

Regards,
Soundara Rajan S.


VS Vance Sankar replied to Soundara Rajan S October 1, 2015 09:21 PM UTC

Hi Hemraj,

Thanks for contacting Syncfusion support.

We have already exposed the SubReportModel property in WebAPI(IReportController) side. By using this, you can pass the DataSource values to Sub Report on Report Loaded method as shown in the below example,

        Public void OnReportLoaded(ReportViewerOptions reportOption)

        {

            if (reportOption.SubReportModel != null)

            {

                DataSourceValus val = new DataSourceValus();

                reportOption.SubReportModel.DataSources.Add(new ReportDataSource()

                {

                    Name = "DataSet1",

                    Value = val.GetDataSource()

                });

            }

            else

            {

                DataSourceValus val = new DataSourceValus();

                reportOption.ReportModel.DataSources.Add(new ReportDataSource()

                {

                    Name = "DataSet1",

                    Value = val.GetDataSource1()

                });

            }

        }


We have prepared a sample and it can be downloaded from the below location,
http://www.syncfusion.com/downloads/support/forum/120653/ze/SubReportDemo15842735.zip

Regards,
Soundara Rajan S.

So based on your response:

Once a SubReportModel is set it creates a Datset1, from  the DataSource to populate the SubReport. If the SubReportModel is not set, then it populates the same Dataset1 on the Main report.

Is it possible to use 2 different datasets, one to populate the main report and the other to the sub report?




SM Sundaraj Muthunarayanan Syncfusion Team October 2, 2015 01:38 PM UTC

Hi Hemraj,

Thanks for the update.

Yes, We can load to two different dataset to main report and sub report as shown in below code snippet.

PublicvoidOnReportLoaded(ReportViewerOptionsreportOption)
{
if(reportOption.ReportModel.ReportPath.Contains("ParentReportName"))
{
// To load mainreport datasource //
DataSourceValusval =newDataSourceValus();
reportOption.ReportModel.DataSources.Add(newReportDataSource()
{
Name ="DataSet1",
Value = val.GetDataSource1()
});
}
else if(reportOption.SubReportModel !=null)
{
// To set subreport datasource //
DataSourceValusval =newDataSourceValus();
reportOption.SubReportModel.DataSources.Add(newReportDataSource()
{
Name ="DataSet2",
Value = val.GetDataSource()
});
}
}

In above example, the ReportLoaded method will be invoke while loading each main and sub reports. So you can pass your data source values to sub report through SubReportModel property.

Regards,
Sundaraj M.


Loader.
Live Chat Icon For mobile
Up arrow icon