Monday, February 20, 2012

page number & records number

1. how to show page number & total page number in report body?

2. how to show total records number?

For #1: Create a text box. For the value, enter the following:

="Page " + Globals!PageNumber.ToString() + " of " + Globals!TotalPages.ToString()

For #2: If you just want to show the number of rows in a table for example, then create a text box, and enter the following:

=CountRows(Fields!FieldName.Value)

|||

thanks for reply, but errors found.

for #1:

[rsPageNumberInBody] The Value expression for the textbox ‘textbox1’ refers to the global variable PageNumber or TotalPages. These global variables can be used only in the page header and page footer.

for #2:

[rsInvalidAggregateScope] The Value expression for the textbox ‘textbox2’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a data set.

pls advise, thanks

|||

for #1: I can't think of another way to output the page numbers, so you might have to just use the header and footer to handle it.

for #2: Create a text box and enter the value: =CountRows("DataSetName")

This will output the number of rows returned by the dataset.

|||for #2 is work. thanks.|||

Okay, I found a solution for #1:

Go to "Report" -> "Report Properties" -> "Code"

In the Custom Code section, enter the following:

Public Funtion 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


Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

|||I cannot get this to work. I get an end of statement expected error for the first line. I copied the code into report, report properties, code tab and change the function names to suit my naming convention. Also, when I try to refer to the functions in a textbox Code.FunctionName does not recognize the function in the custom code section.|||

Okay, I found the error. When I typed in the code for the post, I spelled "Function" incorrectly on the very first line... Just add the missing "c" and you will be good to go. Sorry about that.
Joel

|||

ah, it's okay... I don't know why I didn't notice that. I got the code in without any errors this time. When I test it, it doesn't seem to function as desired.

= Code.FunctionName()

I only get the number 1 in all the textboxes that carry the above information.

|||

Can you copy and paste your custom code as well as your expression for the textbox?

Thanks,
Joel

|||

Custom Code

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

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

in Text Boxes in Tables

=Code.PageNumber() & " " & Code.TotalPages()

I'm running VS2k5 & SSRS2k5. My report has two columns, and runs about 200 pages. I have two tables, and I'm trying this in both tables in group headers and detail lines. All I get for all the text boxes is "1 1". I hope this information helps. I know I specified earlier that I changed the function names for our naming conventions, but I decided to go with exactly what you have until I can get it to work, then I'll make any necessary changes.

Thanks!

Curtis

|||

Hmm, I'm also getting the same results. I think it's safe to say I didn't test this very well. When I first wrote the function, I tested it on a report with only one page and when it outputed "Page 1 of 1", I figured it was good to go. However, after playing around with a report that is 3 pages, it's clear this function is not going to work.

I'm not really sure why we are only getting the value 1 for both globals. It is clearly accessing these globals because if you change their names it will create an error saying they are not members of "Globals". Anyway since that didn't work, I really can't think of another idea on how to output page # and total pages in the body. If you come up with a solution though, I'd be interested to see it.

Thanks,
Joel

|||

I'll see if there is anything I can come up with! If anyone else has any ideas or thoughts, feel free to share! I just do not understand why SSRS should not allow us to use pagenumbering in the data. It doesn't seem to make much sense to me.

Thanks,

Curtis

|||

Okay, so I have a solution that works for me. I do not know if it will be a fix all for everyone interested, but I would like to share anyway. I was talking to our SQL developer about my issues with using page numbering in my data. In my case, I am building a table of contents. He intrigued me when he asked me if I thought about using my SELECT statements to predict my page numbers off of my row numbers. I can use this, because I found in my main report I had to define x number of rows per page to keep multiple detail lines of my table together. What I did in SQL is this:

SELECT

,...

, ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC) AS ROWNUMBER

, ((ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC)) / 50) + 4 AS PAGENUMBER

...

I determined my table of contents will always be three pages, and I know that I have fifty rows per page. I have run my 200+ page report and compared random sections in my TOC to my report, and I found it was accurate. If there are any questions, please feel free to ask. I would be more than happy to clarify if it is necessary.

|||Thanks for the post. I was thinking about trying something like that myself, good idea.

No comments:

Post a Comment