Imagine you have to create a report, for example a Document, and there’s certain information, like for example Sales Conditions, that only need to be printed on the footer of the last page. How do you do that in RDLC?
A good thing is always to investigate if there’s a property that you can use. In this case the properties of a header and footer that could help us are: PrintOnFirstPage and PrintOnLastPage. But actually, these two properties allow us to NOT print something on the First and/or Last page, and what we want is the other way around. So, bad luck, these properties will not help us.
Then let’s have a look at the Globals collection. Here we have two interesting Globals:
- Globals!PageNumber
- Globals!TotalPages
So, let’s try to use them.
When you use these in a textbox in the body of a report you will get an error:
So adding a textbox to the body of the report and determining via an expression if we are on the last page and then showing/hiding it is not an option. Why would we do this you might think. If you place something at the bottom of the Body it is automatically shown only on the last page, no? Well, in Dynamics NAV Document reports, the Body contains a List, putting it in the List would make it appear on every page and putting it below the List is not an option, because it needs to be shown on the last page, for everydocument.
No problem, let’s put it where it’s allowed, for example the Footer.
To be able to show a field in the dataset on a Footer (or Header) we will need to declare a Variable, a Set function and a Get function:
Shared LastPageInfo as Object Public Function GetLastPageInfo() as Object Return Cstr(LastPageInfo) End Function
Public Function SetLastPageInfo(NewData as Object) If NewData > "" Then LastPageInfo = NewData End If End Function
Now we will create a Layout:
The textbox in the Footer is inside a Rectangle and in the Hidden property of the Rectangle we can set the following expression:
And voila the result:
Here you can download the example: InfoOnLastPage v1, and here is the example in NAV 2015: ShowOnLastPage
By the way, on some blogs you might see a solution to be able to show the PageNumber and TotalPages on the Body of the report using an expression like the following:
Function PageNumber() As String Return Me.Report.Globals!PageNumber End Function
But unfortunately it does not work and always shows 1 as the PageNumber (same for TotalPages). Actually there’s a mention on it on Microsoft Connect here. Were basically the answer from Microsoft is: “We will consider adding this as a new feature in a supported, declarative way via RDL ReportObjectModel enhancements in a future release, and in the meantime also monitor customer vote counts.”
I have also tested it on Microsoft Dynamics NAV 2013, with the same result. Maybe when we switch over to RDLC2010 it might become possible 🙂
Discover more from think about IT
Subscribe to get the latest posts sent to your email.
Pingback: Show a Footer Only on the Last Page? | Pardaan.com
By using this, would this not only show up on the last page instead of on the last page of every document? In fact, how would you be able to determine if the current page is the last page of a document?
I can imagine adding a field in the dataset that shows the document number of the next record, and if that record is processed in the list where next document number != current document number (it can also be empty for the last document) then you are on the last page.
Though doing so would leave you with one last bit of trouble, using the footer would leave that amount of space reserved on every page, a white space on all pages except the last of each document where the contents of the footer would not be hidden.
Hi nice article by the way. I have one question how would eliminate the space taken by the hidden footer on the first page/other page. your solution actually hides the field but the space of the footer is actually in the report with black data.
Unfortunately even when hiding a Footer the Report Viewer will still reserve the space for it. The only way to avoid this is by not using a Footer and by putting it in the Body, but there we can’t access the PageNumber. I’m hoping Microsoft one day will give access to PageNumber in the Body, that would solve so many problems… 🙂