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
.
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.
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.
To display the Report Data pane In Design view, on the View menu, select Report Data, or use CTRL+ALT+D.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With