Share via


"Continued" Header on Subsequent Pages

Question:
How can I repeat a group header on each page, but have it say "MyGroup (continued)" on all but the first page?

Answer:
Since pagination is determined long after the report has been fully processed, there's no way for the body of the report to reference any page information.  As a result, we're going to have to resort to a trick wherein something in the page header can be made to look as if it is the group header.

The following assumes you are using a table and have no table header but can be readily adapted to other situations.

Step 1:   Turn off RepeatOnNewPage on your group header

Step 2:   Duplicate the group header information in a hidden column
You're going to need the group header text to always be present on the page, even when the group header itself isn't present. The easiest way is to add a hidden column to the table and then copy the group header textbox into the detail row in that column. Make careful note of the names of both the group header textbox (which I'll call GroupHeader) and the copy (which I'll call GroupCopy)

Step 3:   Copy the first GroupHeader and first GroupCopy to the page header
In the page header, add two textboxes with the following expressions:
   =First(ReportItems!GroupHeader.Value)
=First(ReportItems!GroupCopy.Value)
Make careful note of the names of both these textboxes (which I'll call FirstGroupHeader and FirstGroupCopy).  Run the report and notice the behavior:  FirstGroupHeader is the same as FirstGroupCopy only if it appears at the top of the page.  Mark both textboxes as Hidden=True

Step 4:   Copy the GroupCopy textbox into the page header and add "continued"
In the page header, add a textbox with the following expression:
   =First(ReportItems!GroupCopy.Value) + " (continued)"
Align and size the textbox to match the GroupHeader textbox exactly.  Now when you run the report, you'll see both the normal group header and the Continued group header

Step 5:   Conditionally hide the Continued header textbox
Ideally, the next step would be to set the Hidden expression on the Continued header textbox to this:
=ReportItems!FirstGroupHeader.Value=ReportItems!FirstGroupCopy.Value
Unfortunately, this won't work due to a slightly overzealous publishing restriction against using multiple report item references within a single expression in a page header item [which was intended to prevent potentially bad things like Sum(textbox1/textbox2)].
However, we can bypass this publishing restriction by passing in the report items collection to a custom function.
Add the following to the report's Code block:
public function HideHeader(Items as ReportItems) as Boolean
return Items("FirstGroupHeader").Value = Items("FirstGroupCopy").Value
end function
Now set the Hidden property of the Continued header to:
   =Code.HideHeader(ReportItems)

Note: In the event you will always page break at the end of a group, there is a much simpler approach. You can skip steps 3 and 5 and instead set the Hidden property of the Continued header to:
   =Not(ReportItems!GroupHeader.Value Is Nothing)

A full working sample of continued headers on subsequent pages is attached.

Continued.rdl