none
Adding subreport (RDLC) RRS feed

  • Question

  • Hi, Everyone!

    I just can't seem to find a working example of adding a subreport without any parameters to an existing report. (RDLC)

    I'm not sure how to fill the subreport properties: "Name" & "Use this report as subreport".

    I would like to also mention that my subreport is location under a different folder in my project.

     

    Please advice,

    Thanks!

    Tuesday, July 27, 2010 1:46 AM

All replies

  • To add a subreport in design mode:

    First design the subreport separately. Then in the main report add a subreport item and set its ReportName property to the name of the subreport file (without the .rdlc extension.)

    ReportViewer will load the .rdlc corresponding to the subreport automatically—if it can find it. If the subreport .rdlc is in the same location as the main report .rdlc then ReportViewer will be able to find it.

    However if you loaded the main report using the LoadReportDefinition method then ReportViewer does not know where to look for the subreport .rdlc. In this case you should use the LoadSubreportDefinition method to supply the .rdlc corresponding to the subreport. Note that unlike in the case of drill-through reports, ReportViewer needs the subreport definitions before processing the main report.

     


    Ali Hamdar (alihamdar.com)
    Wednesday, July 28, 2010 7:07 AM
  • This is exactly what I'm trying to do but I get this error message when trying to load the report:

    The subreport 'CompanyHeader' could not ne found at the specified location CompanyHeader. Please verify that the subreport has been published and that the name is corrent.

    On the subreport properties there are 2 fields: Report Name & "Use this report as subreport". What should I set the second one to?

    First try (doesn't work):

                Assembly _assembly = Assembly.GetExecutingAssembly();
                StreamReader subReport = new StreamReader(_assembly.GetManifestResourceStream("GUI.Reports.CompanyHeader.rdlc"));

                this.reportViewer1.LocalReport.LoadSubreportDefinition("GUI.Reports.CompanyHeader.rdlc", subReport);

                this.reportViewer1.RefreshReport();

    Second try (doesn't work):

                StreamReader subReport = File.OpenText(@"C:\Development\Personal\Visual Studio 2010\MyApp\GUI\Reports\CompanyHeader.rdlc");
                this.reportViewer1.LocalReport.LoadSubreportDefinition(@"C:\Development\Personal\Visual Studio 2010\MyApp\GUI\Reports\CompanyHeader.rdlc", subReport);

                this.reportViewer1.RefreshReport();

    Can you show me some code??

    Wednesday, July 28, 2010 1:29 PM
  • Use the name you specified in the subReport properties on the parent report.  I set both fields in the general tab to the same name.

    Assembly _assembly = Assembly.GetExecutingAssembly();
                StreamReader subReport = new StreamReader(_assembly.GetManifestResourceStream("GUI.Reports.CompanyHeader.rdlc"));

                this.reportViewer1.LocalReport.LoadSubreportDefinition("CompanyHeader", subReport);

                this.reportViewer1.RefreshReport();

    Thanks

    Terry

    Thursday, September 9, 2010 9:16 AM