4

Please consider this custom report:

report layout

I want to generate that page number automatically on all pages. I have some landscape pages. I want to place the page number in the footer, but I have problem with this in landscape reports because footer in landscape reports place in bottom of the page not in right of the page so I should place page number in body section.

How I can place a page number in the body section?

Arian
  • 12,793
  • 66
  • 176
  • 300

3 Answers3

4

I don't think this will be possible unless you get creative.

Without having the program on hand at the moment I hope this could start some thinking.

Try add an exrta column to your data counting the nuber of rows and force a page break every x rows. If that works you may be able to play with some formatting to get it visualy right.

Wow good luck!

glh
  • 4,900
  • 3
  • 23
  • 40
4

This article may be of some use: Determine page number in SSRS

Determine page number in SSRS

This method takes advantage of SQL Server’s new ranking functions and can be used in your SQL Reports to determine the page number in the body of a report and also possibly act upon that information to hide/display columns.

Use this method if:

  1. You have a preset limit of how many records display on a page
  2. You have grouping and each group shows on its own page
  3. You can accurately calculate the number of records on each page

Solution in article uses the Ranking Functions in SQL, well worth a look to see if it is applicable.

So I mentioned there were 3 scenarios where this could work for you. I’ll give an example on how to do each and let your creativity do the rest. This will server as our sample sales table:

name     sales_amount    group_name  Scenario #1     Scenario #2     Scenario#3
A        10              A1          1               1               1
B        20              A1          1               1               1
C        30              A1          2               1               1
D        30              A2          2               2               1
E        40              A3          3               3               2
F        40              A3          3               3               2
G        50              A4          4               4               2
H        60              A5          4               5               2

Scenario #1:

You have a preset # records to be places on each page: Here’s what your SQL Query would look like:

DECLARE @rows_per_page INT
SET @rows_per_page = 2
SELECT
 employee.name
 ,page = (Row_Number() OVER ( ORDER BY employee.sales_amount ) / @rows_per_page)
FROM
 employee

In SSRS you can then create a parent group in your tablix (SSRS 2008) and set the option to break “Between each instance of a group”. (Page Breaks tab in SSRS 2008)


Scenario #2:

You have grouping and each group shows on its own page

SELECT
 employee.name
 ,page = Dense_Rank() OVER ( ORDER BY employee.group_name )
FROM
 employee

On your report in SSRS, on the group properties for the table/matrix/tablix set the option to break “Between each instance of a group”. (Page Breaks tab in SSRS 2008)


Scenario #3:

You can accurately calculate the number of records on each page If you can accurately calculate the number of records on each page, it becomes an easy task to use a similar methods as in #1. In the example, the number was 4 records per page.

Matthew Warman
  • 3,234
  • 2
  • 23
  • 35
2

Use this: Access Page number in report body In SSRS

Or this: http://social.msdn.microsoft.com/forums/en-US/tfsreporting/thread/b901c9b4-320e-4fbc-afa9-495d5566c168/

You just need to create custom code for the report and then reference that code where you want (referenced from the second link):

With the Data or Layout tab view active select "Report" -> "Report Properties" On the "Report Properties" dialog select the "Code" tab In "Custom code:" add the new Functions to get the page numbers:

Public Function PageNumber() as String
     Dim str as String
     str = Me.Report.Globals!PageNumber.ToString()
     Return str
End Function

Public Function TotalPages() as String
     Dim str as String
     str = Me.Report.Globals!TotalPages.ToString()
     Return str
End Function

Use it like:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()
Community
  • 1
  • 1
Neil
  • 911
  • 7
  • 25
  • 1
    the problem is page number in body section repeated in every rows – Arian Dec 08 '12 at 20:53
  • Whereas this answer is not solve my problem I mark it as answer – Arian Dec 09 '12 at 20:17
  • This might not be an optimal solution by look at this: http://forums.asp.net/t/1347596.aspx/1 You basically put the field in the row header and then have the row header repeat on every page. Also, if doing this makes the other headers show up on every page and you don't want that to happen, you can go to the visibility of those fields and change to visibility to something like =IIF(Code.PageNumber() = 1, TRUE, FALSE) – Neil Dec 10 '12 at 15:57
  • Also, if you put the code in a text box, in the properties for that text box go to RepeatWith and specify the tablix to repeat it with. This will repeat that text box on every page that the tablix is on. – Neil Dec 10 '12 at 16:12
  • dear Neil in your sample I got just `Page 1 of 1` and when I go to next page this text does not change – Arian Dec 10 '12 at 19:14
  • Did you do it with it's own textbox or as part of the tablix? – Neil Dec 10 '12 at 19:20
  • I do it with text box and place text box in out side of tablix but inside `Body` section – Arian Dec 10 '12 at 19:27
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20892/discussion-between-kerezo-and-neil) – Arian Dec 10 '12 at 19:41
  • Hi, `Global!` values are only accessible in header and footer section of the report, another solution i encountered can be found in the following [article](http://www.easkills.com/ssrs/determinepagenumberinssrs20052008), where you calculate the page number based on report data. Extracts of the article were also posted as an answer. – Matthew Warman Jan 07 '13 at 09:57