SSRS Subreport Problem RRS feed

  • Question

  • I have an SSRS local report (.rdlc) that contains a subreport.  I want to be able to dynamically load the subreport format so that I can provide customizations per customer.  The code I'm using seems to do everything its supposed to except that when the report is rendered it always contains the subreport format that was embedded in the main report when it was built and the loaded subreport appears to be ignored.  Here is my code:

            public virtual void RenderReport(SsrsReportTypes reportType)
                LocalReport report = new LocalReport();
                report.ReportEmbeddedResource = "Spheris.InvoiceAdmin.Reports.DefaultInvoice.rdlc";
                report.LoadSubreportDefinition("bodySubReport", GetSubreportStream());
                report.SubreportProcessing += new SubreportProcessingEventHandler(OnSubreportProcessing);
                report.DataSources.Add(new ReportDataSource("InvoiceReportTranscriptionLineItems", (IEnumerable<InvoiceReportTranscriptionLineItem>)TranscriptionItems));
                report.DataSources.Add(new ReportDataSource("InvoiceReportAddOnCharges", (IEnumerable<InvoiceReportAddOnCharge>)AddOnCharges));
                string mimeType, encoding, extension;
                string[] streamIds;
                Warning[] warnings;
                RenderedReport = report.Render(SsrsReportTypeToString(reportType), null, out mimeType, out encoding, out extension, out streamIds, out warnings);
    Does anyone have any ideas what I'm doing wrong?  "bodySubReport" is the name of the subreport control inside the main report.  I'm thinking that I must not be correctly associating the loaded subreport to the embedded subreport control somehow.  I've run out of ideas.


    Thursday, December 10, 2009 2:05 PM


  • Since you are loading the main report definition from ReportEmbeddedResource, the call to LoadSubreportDefinition is being ignored.  LocalReport will combine the main report resource name with the subreport name and load the corresponding embedded resource automatically.  If you load the main report definition from a stream using LocalReport.LoadReportDefinition(), then your code will do what you want.
    Tuesday, January 5, 2010 7:29 AM