How to populate a dataset in an SSRS subtitle?

It seems like it should be trivial, but I'm having difficulties.

I have a main report, I fill in the data sets as shown below in ReportViewer.aspx.cs.

 ReportViewer.LocalReport.ReportPath = "~/SummaryReport.rdlc"; ReportDataSource requestsSource = new ReportDataSource(); requestsSource.Name = "RequestHeadersDataSet"; requestsSource.Value = GetSummaryRequestsDataSet(); // Returns DT ReportViewer.LocalReport.DataSources.Add(requestsSource); 

I also have a subreport that my main report refers to in a row group in a table. The dataset has a RequestName column. I pass this through the Subreport properties on the Options tab.

As soon as I add a data set to the data set, I get the error message: Data retrieval failed for the subreport. No wonder, given that I never filled in anything.

But how can I add a subreport to the data source? The report path for ReportViewer is set to my main report.

Both use the same dataset, if that makes any difference.

+5
source share
1 answer

To set up a data source, you need the SubreportProcessing Event . See also walkthrough .

 ReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(exampleSubreportProcessingEventHandler); void exampleSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e) { e.DataSources.Add(new ReportDataSource("SubReportDataSet", GetSummaryRequestsDataSet())); } 

From the provided link SubreportProcessing Event .

The SubreportProcessing event is fired for each instance in the main report, and not just for each report definition. If the report contains multiple instances nested with the same report definition, this event is fired for each instance.

If there are several subscriptions in the main report, you can examine the ReportPath Property of the SubreportProcessingEventArgs class to determine which subreport is being processed and provide data for this subreport.

+3
source

Source: https://habr.com/ru/post/1212651/


All Articles