|
Article relates to
|
Telerik Reporting
|
|
Created by
|
Rossen Hristov, Telerik
|
|
Last modified
|
03 March, 2009
|
|
Last modified by
|
Steve, Telerik
|
HOW-TO
Use data source fields in page sections (PageHeader or PageFooter).
PREREQUISITES
A good understanding of
Report Life Cycle and
Report Sections.
SOLUTION
The
paging of a report strongly depends on the
format it is rendered to. For that reason
Page Sections and their child items are processed by the corresponding rendering extension well
after the report data has been processed. At this moment the report data source is not available anymore and
you cannot use data-bound items directly in the Page Sections.
This, however, does not mean that displaying data based on fields from the data source is not possible. The idea is fairly simple. The
ReportHeader section is used for automatically handling data-bound report items and the resulting values are later "copied" to report items residing in a Page Section.
Unlike Page Sections, the
ReportHeader section is processed during the processing phase of the report life cycle and data is readily available at that moment. Since the ReportHeader section is only one per report, its data context is such that item binding expressions should use
only aggregate functions. That is, the data source has many rows and the ReportHeader is only one, thus only aggregates make sense in such a section.
If an item binding expression used in the ReportHeader specifies a data field without an aggregate, the
First() aggregate function is used by default.
Now, once we have set-up all of the report items that we need in the ReportHeader, we only need to
retrieve their calculated values after the ReportHeader has been processed and
assign them to the respective items in the Page Section.
To do that we need to handle the
ItemDataBound event of the Page Section. Remember that Page Sections are processed by the respective rendering engine (i.e. PDF, Excel, RTF, etc.), which is
well after the report has been
data-bound, so we are guaranteed that our ReportHeader section is already finished when we enter the
ItemDataBound event of the Page Section. Now the only thing left is to find all items of interest using the
Telerik.Reporting.Processing.ReportItemBase.ItemCollection.Find method, obtain their values and assign them to the respective items in the Page Section.
The process is fairly simple and well-demonstrated in the attached C# and VB.NET sample reports.