http://reddymsbitools.blogspot.com

Saturday, 26 February 2011

Reset Page Number on Group Break

SQL Server Reporting Services provides 2 Global variables: Globals.PageNumber and Globals.TotalPages. You may use these to display page numbers in your "Page Footer." However, suppose you need to "reset" the page number whenever a "group" in your RDL breaks. For example, say you are displaying customer invoices and you want the page number to reset on each new customer. This is such an obvious requirement, but unfortunately there is no native support for this in the reporting services.
Possible Solution

Initially, we were very happy to find a similar solution at Chris Hay's Weblog. In fact, there are some other interesting articles too at his Weblog that are worth reading. His solution really lies in using the "shared" variables. Precisely, add a custom function to set the shared variables and retrieve the group page number.
Collapse

Public Function GetGroupPageNumber(group as Object, pagenumber as Integer) _
as Object
If Not (group = currentgroup)
offset = pagenumber - 1
currentgroup = group
End If
Return pagenumber - offset
End Function

Use the function in the page header or footer:
Collapse

=Code.GetGroupPageNumber(ReportItems!Category.Value,Globals!PageNumber)

No comments:

Post a Comment