2

In RDLC reports, we are planing to use a sub report as the report header to avoid code duplication and to keep the consistency across all the reports.

However RDLC does not allow to add sub reports in the header section. Hence we can only add it to the body. When adding to the body, sub report is only visible in the first page. We need to display it as the header in all the pages.

Does anyone has come across a scenario like this and have an idea to achieve this?

Thanks, Wijitha

Wijitha
  • 1,189
  • 2
  • 12
  • 22

2 Answers2

2

You may need to re-think your approach. If you want for ALL reports to have the same header, why don't you use your "header" report as a "main" report and drop other reports into it's body as sub-reports?

Also, you may choose to use Table in the main report and create your "header" in Table header and set it to repeat on each page and add your sub-reports as detail rows. It depends on the logic of your report(s) and if you need any additional grouping or visibility conditions.

InitK
  • 1,261
  • 13
  • 21
  • Can you elaborate more your first suggestion ? – Haider Ali Wajihi Mar 24 '15 at 14:34
  • I'm not sure what you would be interested in. If you give me some details about your problem, I would know what kind of details you may find helpful. Otherwise, there is documentation on the topic available. – InitK Mar 24 '15 at 16:10
  • I go with your first suggestion, but i want to know, how can i put my all reports in the body of a main report dynamically from code in c#. Where as i got the way to do this, when i googled a little more. – Haider Ali Wajihi Mar 25 '15 at 12:48
0

you may also do like this :

  1. put your header content in a separate report
  2. place an image in the header of the main report pointing its source to a dataset field
  3. in your code, first render your header report to an image, then add image as a datasource of the main report, like this:
ReportViewer header_report = new ReportViewer();
header_report.LocalReport.ReportPath=PATH_TO_HEADER_REPORT
byte[]  IMAGE_CONTAINER = rp.LocalReport.Render("Image", "<DeviceInfo><OutputFormat>JPEG</OutputFormat><DpiX>1000</DpiX><DpiY>1000</DpiY></DeviceInfo>");               
// THEN ADD TO THE MAIN REPORT DATASOURCES
main_reportviewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", new List<CUSTOM_OBJECT>() { A_BYTE[]_FIELD=IMAGE_CONTAINER  }));

This should do the trick.

NB : Think of setting the image properties properly so that the rendered image doesn't overflow the box. Also, in the header report make sure to set the report width/height the same as the width/height of the body

Sweet MBH
  • 23
  • 9