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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Breaking change in OnReportLoaded for a report with multiple subreports

Thread ID:

Created:

Updated:

Platform:

Replies:

147317 Sep 5,2019 06:26 PM UTC Sep 9,2019 06:01 AM UTC Report Platform 4
loading
Tags: Report Viewer
Paul West
Asked On September 5, 2019 06:26 PM UTC

I have a report that contains six subreports. The code was originally written for ASP.net Core with Syncfusion 16.3.0.29. I updated to the latest (17.2.0.46) and now the code to assign datasets to each subreport no longer works.

The data is contained in XML files. The subreports and corresponding datasets are named with the main report name + "_{subreport name}". With version 16.3.0.29, OnReportLoaded was called for the main report and each subreport. With version 17.2.0.46, OnReportLoaded is called once only and the report errors with message: "The data input collection null or empty for the data set is used in the report."
...
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
            var fNameWithExtension = reportOption.ReportModel.ReportPath;
            ReportDataSource ds = null;
            var needsDataSet = false;
            DataSet dataset = null;

            if (fNameWithExtension.Contains("AgentDetail"))
            {
                needsDataSet = true;
                ds = GetDataSet(reportOption);
            }

            reportOption.ReportModel.ProcessingMode = Syncfusion.EJ.ReportViewer.ProcessingMode.Local;

            if (reportOption.SubReportModel != null)
            {
                if (reportOption.SubReportModel.DataSources == null)
                {
                    reportOption.SubReportModel.DataSources = new ReportDataSourceCollection();
                }

                reportOption.SubReportModel.DataSources.Add(ds);
            }
            else
            {
                if (dataset != null)
                {
                    foreach (DataTable table in dataset.Tables)
                    {
                        reportOption.ReportModel.DataSources.Add(new ReportDataSource
                            { Name = table.TableName, Value = table });
                    }
                }
                else
                {
                    reportOption.ReportModel.DataSources.Add(ds);
                }
            }
        }
...
        private ReportDataSource GetDataSet(ReportViewerOptions reportOption)
        {
            var fNameWithExtension = reportOption.SubReportModel == null
                ? Path.GetFileName(reportOption.ReportModel.ReportPath)
                : Path.GetFileName(reportOption.SubReportModel.ReportPath);
            var ds = new DataSet();
            ds.ReadXml(Path.ChangeExtension(Path.Combine(DataPath, fNameWithExtension), ".xml"));

            var result = new ReportDataSource {Name = ds.Tables[0].TableName, Value = ds.Tables[0]};
            //(result.Value as DataTable).DataSet.DataSetName = "DataSource1";
            return result;
        }


Mahendran Shanmugam [Syncfusion]
Replied On September 6, 2019 06:13 AM UTC

Hi Paul, 
 
We need to load the multiple subreports based on report path condition and we need to pass the dataset collections also based on report path condition. Please find the below code example. 
public void OnInitReportOptions(ReportViewerOptions reportOption) 
        { 
            string basePath = _hostingEnvironment.WebRootPath; 
            if(reportOption.SubReportModel != null) 
            { 
                if (reportOption.SubReportModel.ReportPath == "SubReport1") 
                { 
                    FileStream subReportStream1 = new FileStream(basePath + @"\ReportRDL\SubReport1.rdlc", FileMode.Open, FileAccess.Read); 
                    reportOption.SubReportModel.Stream = subReportStream1; 
                } 
                else if (reportOption.SubReportModel.ReportPath == "SubReport2") 
                { 
                    FileStream subReportStream2 = new FileStream(basePath + @"\ReportRDL\SubReport2.rdlc", FileMode.Open, FileAccess.Read); 
                    reportOption.SubReportModel.Stream = subReportStream2; 
                } 
            } 
            else 
            { 
                FileStream reportStream = new FileStream(basePath + @"\ReportRDL\MainReport.rdlc", FileMode.Open, FileAccess.Read); 
                reportOption.ReportModel.Stream = reportStream; 
                reportOption.ReportModel.DataSources.Clear(); 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet", Value = MainReport.GetData() }); 
            }            
        } 
 
        public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            if (reportOption.SubReportModel != null) 
            { 
                if (reportOption.SubReportModel.ReportPath == "SubReport1") 
                { 
                    reportOption.SubReportModel.DataSources = new ReportDataSourceCollection(); 
                    reportOption.SubReportModel.DataSources.Clear(); 
                    reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = SubReport.GetData() }); 
                } 
                else if (reportOption.SubReportModel.ReportPath == "SubReport2") 
                { 
                    reportOption.SubReportModel.DataSources = new ReportDataSourceCollection(); 
                    reportOption.SubReportModel.DataSources.Clear(); 
                    reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet2", Value = SubReport.GetData() }); 
                } 
            } 
        } 
 
We have prepared the simple sample for your reference and it can be downloaded from below location. 
 
Regards, 
Mahendran S. 


Paul West
Replied On September 6, 2019 02:03 PM UTC

The difference between your code and mine is that the dataset for the main report is loaded in OnInitReportOptions. With version 16.3.0.29, the dataset for the main report is loaded in OnReportLoaded.

I will make the change and report back.

Paul West
Replied On September 6, 2019 02:22 PM UTC

Yes, that was it. For anyone updating from version 16.x to 17.x, this is a quick fix.

Thank you for the quick response!

Vinoth Srinivasan [Syncfusion]
Replied On September 9, 2019 06:01 AM UTC

Hi Paul, 
 
Thanks for your update. 
 
We were able to reproduce the mentioned dataset collection null issue when we are passing the dataset collection in OnReportLoaded method. We will fix this issue and it will be reflected in our upcoming weekly NuGet release. As of now we suggest you pass the dataset collection in OnInitReportOption method to avoid the mentioned problem at your end. 
 
Regards, 
Vinoth S. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon