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.
Unfortunately, activation email could not send to your email. Please try again.

Subreports

Thread ID:

Created:

Updated:

Platform:

Replies:

120653 Sep 30,2015 04:59 PM Oct 2,2015 09:38 AM ASP.NET MVC 3
loading
Tags: ReportViewer
Vance Sankar
Asked On September 30, 2015 04:59 PM

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.



Soundara Rajan S [Syncfusion]
Replied On October 1, 2015 03:24 AM

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.

Vance Sankar
Replied On October 1, 2015 05:21 PM

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?



Sundaraj Muthunarayanan [Syncfusion]
Replied On October 2, 2015 09:38 AM

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.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;