SSRS - Displaying the page number in the body shows previous page number.

Michael Allen (SXS UK) 0 Reputation points
2025-03-03T12:41:45.5866667+00:00

Hi,

I have a report containing a tablix with a textbox (TextBox25) that needs to display the current page number.

User's image

In the report code I have:

Public Shared PageNumber as Integer

Public Function ChangePageNumber(ByVal PageNum As Integer)

PageNumber = PageNum

End Function

Public Function GetPageNumber()

Return PageNumber

End Function

In the header I have a hidden textbox with: =Code.ChangePageNumber(Globals!PageNumber)

And in TextBox25 I have: =Code.GetPageNumber()

This results in:

User's image

Where the first page number in the list should match the page number shown in the footer.

Can you please tell me why this is failing to work as expected? All sources tell me that the header event should always be processed first, then the body event.

I am previewing the report in Microsoft Visual Studio Professional 2022 (64-bit) using Microsoft SQL Server Reporting Services Version 16.0.20143.0.

Regards

Mike

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,006 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ZoeHui-MSFT 41,206 Reputation points
    2025-03-04T03:29:05.1633333+00:00

    Hi @Michael Allen (SXS UK)

    The incrementation of page numbers relies on the triggering of page breaks. If the pagination logic is not configured correctly (e.g., group-based pagination or table-based pagination), it may result in incorrect page numbering.

    Per my research, it is a bit hard to use page number in the body.

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.