I told Fulano and some other people that I would do a walkthrough for preprocessing reports to get page numbers in an index or table of contents RDLCs, much like I worked out a plan for "Group <X> of <Y>" numbering for server mode reports. As you may remember, it wasn't a trivial process, requiring a two parter here.
"How hard can it be?"
Doing it again for RDLCs, which I thought would be a trivial exercise, is turning out to be harder than imagined, for an entirely unexpected reason.
As you also may remember, I wrote some pretty dodgy code in the original walkthrough to handle the fact that page numbers need to be stored and evaluated differently for different renderers (for example, HTML versus PDF). This is because pagination has to be taken care of differently by different renderers, depending on their type of output. In addition to having different physical page layouts to fill, each renderer is also free to handle the pagination and body events in whatever order, with whatever collections, fits their needs. For example, a CSV renderer won't have much use for page header material at all.
I've discussed the differences between formatting and data bands a number of times in this blog and won't belabor that point here.
I should have realized… the renderer for local reports inside report viewer is, again, dealing with a different set of conditions and it seems to evaluate events and repeating items differently too. In hindsight, actually, this should have been the first thing I worried about.
Here's what I'm noticing today: when you're repeating table headers on new pages, a table header expression is not re-evaluated each time it is rendered. (This seems to be true in both the in-viewer representation of the report and the PDF and Excel exports).
I guess this is efficient, but damn. I was seeing some problems with how and when the page headers and footers made page numbers available to me, and I was hoping to avoid the whole issue of "when is a page header rendered" by incrementing a page number myself in a header.
It's worked before. It's not working now.
Still thinking about this… I think there's an answer. However, this fact might bite you in the rear for reasons that have nothing to do with page numbers; suppose you want to do something else that changes the table header each time it appears. It probably won't work as expected.