2015-02-04 54 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更新瞭解答您的評論的答案 –

相關問題