Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 387
Mike Avatar asked Jan 21 '11 12:01

Mike


People also ask

How do I display page numbers in SSRS report?

In the Report Data pane, expand the Built-in Fields folder. If you don't see the Report Data pane, on the View tab, check Report Data. Drag the Page Number field from the Report Data pane to the report header or footer.

How do I find the row number in SSRS report?

Just right click on Name column then navigate to Insert Column then select Left. Once you select left, you will see a New blank column is added before the Name column. After that, right click on newly added column then select Expression (fx) from context menu.

How do I view report data in SSRS report?

To display the Report Data pane In Design view, on the View menu, select Report Data, or use CTRL+ALT+D.


2 Answers

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

like image 155
Struan Avatar answered Sep 19 '22 13:09

Struan


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,

=Variables!PageCount.SetValue(Variables!PageCount.Value+1)

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.

=Variables!PageCount.Value

I have taken reference from this answer.

like image 45
pedram Avatar answered Sep 21 '22 13:09

pedram