2015-02-04 28 views
5

这似乎应该是微不足道的,但我有困难。如何填写SSRS子报表中的数据集?

我有一个主报告,我一直在填充数据集为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); 

我也有一个报表,这是我在主报告中的表所引用的行组内如下。该数据集有列RequestName。我通过“参数”选项卡中的“子报表属性”将其传入。

一旦我将数据集添加到子报表中,我收到一个错误:Data retrieval failed for the subreport.不足为奇,考虑到我从未填充过任何东西。

但我怎么能添加到报表数据源? ReportViewer的reportpath被设置为我的主要报告。

两者都使用相同的数据集,如果这是任何后果。

回答

3

您需要使用SubreportProcessing Event来设置数据源。另请参阅以下walkthrough

ReportViewer.LocalReport.SubreportProcessing += 
       new SubreportProcessingEventHandler(exampleSubreportProcessingEventHandler); 

    void exampleSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e) 
    { 
     e.DataSources.Add(new ReportDataSource("SubReportDataSet", GetSummaryRequestsDataSet())); 
    } 

从提供的链接SubreportProcessing Event

The SubreportProcessing event is triggered for every instance of the subreport in the main report, and not just for each subreport definition. If a report contains multiple subreports instances from the same report definition, this event is triggered for each instance.

If the main report has several subreports, you can examine the ReportPath property of the SubreportProcessingEventArgs class to determine which subreport is being processed and supply data for that subreport.

+0

感谢您的答复。当我有多个子报表,每个子报表都有自己的数据集时,这是如何工作的? – Rail24

+0

@ Rail24更新了解答您的评论的答案 –

相关问题