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
1.1. Open the SubReport report (HeaderReport.trdp) in the Report Designer.
1.2. Go to Report >> Data >> Report Parameters.
1.3. Add a new parameter:
-
Name: "title_parameter"
-
Type: String
-
Allow null: Yes (optional)
-
-
Bind a TextBox in the SubReport to that parameter
2.1. Select the TextBox inside the SubReport report where the title should appear.
2.2. Set its Value to:
=Parameters.title_parameter.ValueNow, the TextBox displays whatever the main report passes in.
-
Map the main report value to the SubReport parameter
3.1. Open the main report and select the SubReport header item.
3.2. Go to Inner Report and add a new parameter:
-
Name: "title_parameter"
-
Value: "Your custom title"
-
-
Preview the report with your custom title: