4

Here's what I'm starting with. I have a report with a subreport in it. What makes this subreport unique is that the XML for the subreport rdlc is generated at runtime and the stream then provided to the report viewer. It was pretty much the only way to lay out the data the way we needed it to be. This report by itself works fine.

Now I'm at a point where I want to combine multiple reports. I created a report with a list. Within the list is a subreport pointing to my original report. But I'm stuck trying to figure out how to apply the dynamic subreport since it is a different stream for each report in the list.

We've already done a lot of work on the original report to get to this point, so I don't really want to rethink my approach.

Here's what I've tried so far:

  1. Call LoadSubreportDefinition for my stream when the SubreportProcessing event gets called for each report in the list. I'm pretty sure this doesn't work because you have to do this before the report rendering begins?

  2. Figure out a way to specify an expression for the Name of the dynamic subreport so that I can call LoadSubreportDefinition using a unique ID. For instance, the Name would be something like ="ImageSubreport" + Parameters!ID.Value and I'd call LoadSubreportDefinition("ImageSubreport1", stream1), LoadSubreportDefinition("ImageSubreport2", stream2). This doesn't appear to be possible in the designer, so I don't think it's possible.

Is there some way maybe to generate each report separately, then merge them?

Dan
  • 533
  • 8
  • 29
  • Which version Visual Studio and .Net version you are building with. – DRapp Apr 11 '12 at 18:29
  • With VS 2013 and .NET 4.0 I've the same problem. It loads the main report but not the subreport. How can I access the Subreport Name property to change it dynamically by code? – Cheshire Cat Jul 22 '15 at 12:38

1 Answers1

2

You just need to call LoadSubReportDefinition immediately after calling LoadReportDefinition.

Lets assume the definition for the main report points to the subreport like this:

<Subreport Name="Subreport1">
    <ReportName>MySubReport</ReportName>
    ...
</Subreport>

and you have stream1 representing the main report RDLC, and stream2 representing the sub-report RDLC.

You need to do something like:

this.ReportViewer1.LocalReport.LoadReportDefinition(stream1);
this.ReportViewer1.LocalReport.LoadSubreportDefinition("MySubReport", stream2);
Greg Sansom
  • 20,442
  • 6
  • 58
  • 76
  • Is "MySubReport" the "Name" or "Use this report as subreport textboxes appears." of subreport you set on the Main Report's rdlc subreport properties? – lionheart May 18 '13 at 17:43