将参数从主报表传递到RDLC中的子报表

时间:2012-10-10 12:13:25

标签: c# asp.net rdlc

我有一个在ReportViewer中显示RDLC报告的网页。对于主报告中的每条记录,都有一个子报告。

我需要将主报表中每条记录的3个字段中的数据作为参数传递给子报表存储过程。

主要报告有效,但只是说

  

错误:无法显示子报告

我在两个报告中都定义了所有参数,并且我正在处理localReport_SubreportProcessing事件

C#代码

    protected void Page_Load(object sender, EventArgs e)
{       
    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Refs_MainDs", SqlDs_RefsReportsMain));
    this.ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);
}
void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
    e.DataSources.Add(new ReportDataSource("Refs_SubDs", SqlDs_RefsReportsSub));
}

ASP代码

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="800px" Width="100%" Font-Names="Verdana" Font-Size="8pt" BorderColor="#666666" 
    BorderStyle="Solid" BorderWidth="1px" AsyncRendering="False" ShowPrintButton="False" >
<LocalReport ReportPath="Reports\EOD_Refs_MainReport.rdlc" >
    <DataSources>
        <rsweb:ReportDataSource DataSourceId="SqlDs_RefsReportsMain" Name="Refs_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_RefsReportsSub" Name="Refs_DataSource" />
    </DataSources>
</LocalReport>                             

AND

<asp:SqlDataSource ID="SqlDs_RefsReportsMain" runat="server" ConnectionString="<%$ ConnectionStrings:AlphaConnectionString %>" 
    SelectCommand="rpt_RefsReport_Main" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:QueryStringParameter Name="RefsID" QueryStringField="RefsID" Type="String" />
</SelectParameters>

2 个答案:

答案 0 :(得分:2)

也许它会对你有所帮助:Sub report query based on main report

答案 1 :(得分:2)

我需要更改每个报告的数据集,他们仍然使用相同的数据源,然后在代码中需要为每个数据集设置参数

<rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="False" ShowPrintButton="False" >
<LocalReport ReportPath="Reports\Report_MainReport.rdlc" >
    <DataSources>
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsMain" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsMid" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsSusp" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsRef" Name="EOD_Summary_DataSource" />
    </DataSources>
</LocalReport>                             

<asp:SqlDataSource ID="SqlDs_ReportsMain" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="rpt_HighLevel" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:QueryStringParameter Name="Key" QueryStringField="Key" Type="String" />
</SelectParameters>

每个报告数据源的

等等

在C#中

protected void Page_Load(object sender, EventArgs e)
{       
    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MainLevelDs", SqlDs_ReportsMain));
    this.ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);
}
void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
    e.DataSources.Add(new ReportDataSource("MidLevelDs", SqlDs_ReportsMid));
}

不知道这是否正确,但对我有用!

HTH