Access Page number in report body In SSRS

I want to use Globals!PageNumber in Report body part. How can I access inside Report body?

I am using SQL Server Reporting Service 2008 R2.


Create functions in the code under the report properties:

Page Number:

Function PageNumber() As String    
    Return Me.Report.Globals!PageNumber    
End Function

Total Pages:

Function TotalPages() As String   
    Return Me.Report.Globals!TotalPages    
End Function

Access it in the body via an expression:

=code.PageNumber & " of " & code.TotalPages

Check out Sample Usage of the Concat Function

Unfortunately in Reporting Services (up to RS2008), this will produce "Page 1 of 1" on every page. The problem is that the body is rendered before the header and footer, therefore the code cannot access the correct pagination, since it is determined AFTER all elements in the body.

If your report is basically a large table with predefined number of rows on each table, try using row_number in your SQL as a workaround to manually calculate page numbers:

you can't use page number in body. use it only in report footer or header.

For that you need to use Report variables:

Go to Report Menu from main Menu in Visual Studio, > Click on Report Properties > Add new variable - named as PageCount (Default value to 0)

Then inside header of footer create one textbox and set below expression,


It will automatically increase for each page.

NOTE: Do not hide it from header or footer, the SetValue will not work if you hide the box, so change the font of textbox to white color. (Do whatever you want but just do not hide it. Then you can use below expression to fetch pagenumber value inside report body.


I have taken reference from this answer.

Need Your Help

Converting float decimal to fraction

php math floating-point type-conversion rational-numbers

I am trying to convert calculations keyed in by users with decimal results into fractions. For e.g.; 66.6666666667 into 66 2/3. Any pointers?