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
close icon
If you became a customer of the Syncfusion Reporting Platform or the Report Viewer, Report Designer, or Report Writer components before October 2019 and have questions related to those products, you can request support through our forum system. However, please note that this support system is only for existing customers who are still using the Syncfusion Reporting Platform or its components and not for new customers looking for reporting products from Syncfusion.

For new customers or those with general reporting questions, we recommend contacting our support team at https://support.boldreports.com/, which is a separate brand created by Syncfusion for its reporting solutions. Our team will be happy to assist you with any questions you may have.

Thank you for choosing Syncfusion for your reporting needs.

Breaking change in OnReportLoaded for a report with multiple subreports

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;
        }


4 Replies

MS Mahendran Shanmugam Syncfusion Team 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. 



PW Paul West 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.


PW Paul West 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!


VS Vinoth Srinivasan Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon