Thursday, January 6, 2011

How to embed subreports in a RDL report

  1. Create reports Main.rdlc and Sub1.rdlc, Sub2.rdlc, Main.rdlc will be the main report and Sub1.rdlc and Sub2.rdlc will be the subreports embedded into Main.rdlc, 
  2. add two "Subreport" elements to the Main.rdlc, with each element's reportname field set to "Sub1.rdlc" and "Sub2.rdlc" respectively,
  3. create a winform and add a reportviewer to it, set the report for the reportviewer to be "Main.rdlc", name the reportviewer rpv
  4. open "View Code" on the winform, and in the constructor add "rpv.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);"
  5. add a method "void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)" to the winform code, now create two List<Object> for each subreport in the method, and add "e.DataSources.Add(new ReportDataSource("Accounting_Core_Purchase_MiscPurchaseLine", [List<Object>]));" for each subreport

No comments:

Post a Comment