Creating Reusable Report Headers and Footers with SubReport
The SubReport item is perfect for creating reusable report components that can be embedded in larger reports later. It can be useful for creating, for example, report or group headers and footers.
Here's a step-by-step tutorial for creating a reusable part of a report (for example, header and footer) using a SubReport:
Creating the Header Report
-
Create a new report (for example,
HeaderReport.trdp). -
Remove the default page header and footer.
-
Add elements like company logos and report titles in the Detail section.
-
Preview and save this report as a standalone file. This will serve as your reusable header part of a bigger report.
Creating the Footer Report
-
Create a new report (for example,
FooterReport.trdp). -
Remove the default page header and footer.
-
Add elements like information text or any other meaningful content to the Detail section of a report.
-
Preview and save this report as a standalone file. This will serve as your reusable footer part of a bigger report.
Adding SubReports to Your Main Report
-
Create a new report that will serve as the main report.
-
Remove the default page header and page footer if not needed.
-
Add a report header and a report footer.
-
Select the Report Header section and add a SubReport item.
-
Navigate to the INNER REPORT section and select the UriReportSource option.
-
For the Uri field, select the
HeaderReport.trdp. -
Select the Report Footer section again and add another SubReport item.
-
Navigate to the INNER REPORT section and select the UriReportSource option.
-
For the Uri field, select the
FooterReport.trdp. -
Select the Details section and add a TextBox item with a sample text.
-
Preview the report which contains reusable header and footer subreports.
Thus, you can create separate reports that serve as standalone report parts and can be reused in multiple reports according to the specific requirements.
Passing Data to SubReports
Instead of using fixed data in the report headers/footers, it is possible to pass a title (or any text) from a main report to a TextBox in a SubReport, using the parameter‑passing mechanism. The above example can be further extended by replacing the "Telerik Reporting" text in the HeaderReport.trdp with a value coming from the main report.
Here are the steps to pass a title from the main report to a TextBox in the SubReport:
-
Define a parameter in the SubReport:
-
Open
HeaderReport.trdpin the Report Designer. -
Select the report and expand Data > Report parameters.
-
Add a new parameter with these settings:
- Name:
title_parameter - Type:
String - Allow null: selected (optional)
- Allow blank and Mergeable: selected, as shown in the example
- Auto-refresh, Multi-value, and Visible: cleared
- Text and Value: empty
Select Save to add the parameter.
- Name:
-
-
Bind a TextBox in the SubReport to that parameter:
-
Select the TextBox inside
HeaderReport.trdpwhere the title should appear. -
Set its Value to the following expression:
text=Parameters.title_parameter.ValueThe TextBox displays the title passed from the main report.
-
-
Map the main report value to the SubReport parameter:
-
Open the main report and select the SubReport header item.
-
Expand Inner Report > Report source > Parameters. Keep Type set to
UriReportSourceand Uri set toHeaderReport.trdp.
-
Add a parameter with Name set to
title_parameterand Value set toYour custom title, then select Save.
-
-
Preview the report. The header now displays
Your custom titleabove the main report's sample text,My First Report.