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

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 01:13 AM

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 09:03 AM

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 09:22 AM

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 01:01 AM

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