I have a web page that displays an RDLC report in a ReportViewer. For each record in the main report there is a subreport.
I need to pass the data from 3 fields from each record in the main report as a parameter to the subreports stored procedure.
the main report works but it just says
Error: Subreport could not be shown
I have all the parameters defined in both reports, and I’m handling the localReport_SubreportProcessing event
C# Code
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 Code
<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>
I needed to change the data set for each report they all still use the same data source and then in code you need to set the parameters for each data set
and so on for each Report Data Source
in C#
Don’t know if it’s the correct way to do it but it works for me!
HTH