About the rendering order in RDLC reports

Recently, I was wondering about the order in which the three sections of a RDLC report, namely header, body and footer, are being rendered. Searching the net, I found this remarkable answer for the question about the rendering order, which is now about 5 years old, but seems still to be valid…
“By default, the execution order is un-documented. In other words, please don’t design a report depend on the exection order.” (Jin Chen)
This sounds pretty strange with regard to two points:
At first, I always thought, that every important fact should be documented, by default. At second, many people designing RDLC reports for NAV rely on the fact, that the body is rendered (executed) before the header, otherwise, the Setdata-/Getdata method, or the improved SetFields method (see one of my recent blog posts) wouldn’t always work.

In order to clarify these things, I set up a simple test report:
The Integer DataItem is filtered from 1 to 100. The PreviewMode has been set to PrintLayout.
With the Tenner column, a simple group can be realized within the layout:
The grouping expression is “Tenner”, of course. The GroupHeader is set to repeat on every page. The expression is the same for all colored textboxes,
where the IncrCountr function simply increments an integer variable named countr, and returns it (note, that for this example, countr needs not to be defined as Public):
The preview of the report is quite interesting:
On the first page, it is clearly seen, that the body is executed before the header and the header is executed before the footer. Furthermore, the GroupHeader is executed before the repeating details and the GroupFooter is executed after the details.
But, by further inspection, it looks strange, that countr value 27 is missing on the first page. So lets take a look on the second page:
There it is, the missing 27. It looks like, the rendering machine has decided to take this row onto the following page, after the function call to IncrCountr(). Furthermore, the repeating GroupHeader is not rendered again, but has kept its old value 25 on the second page.
The last page is as expected:
After the last group footer, the table footer is rendered, followed by the page header and footer.

So, basically, two important facts can be deduced from the test:
1.) The rendering (execution) order is: Body1-Header1-Footer1-Body2-Header2-…
2.) Sometimes one or more rows, which have already been rendered at the bottom of a page body are moved to the top of the following page.

Always keep these two facts in mind, when you set and get global shared variables to be used in various report sections. Other strange things happen, when you do not initially set the PreviewMode to PrintLayout but switch to PrintLayout within the preview window. In this case, the countr variable and may be other variables, too, is not reset to zero. This is clearly a bug. Furthermore in Normal preview mode, the footer seems to be rendered before the header and each time you switch back to the first page, the whole layout seems to be rendered again, resulting in increasing countr values… – so never use normal preview mode, if you encounter any weird things concerning shared variable values.

Here, you can download the sample report for NAV 2015:


One thought on “About the rendering order in RDLC reports

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s