Ever wanted to force an RDLC layout to print a page break dynamically when YOU require it?
Well, it took me some time, but here is a solution/work around to get there.
Let’s begin with the origin of my problem. I am currently converting multiple classic reports to an RDLC layout. (Yay!)
Here I ran into some nice functionality of a previous partner. On text lines of the sales quote they could use a few predefined Standard Text Codes to do formatting. Such as TXTB, TXTBU, etc. (Bold, Bold Underlined, etc.). These are actually no issue to using them in RDLC. Simple add more rows and set the hidden property accordingly. (Hard coded, as was done in classic for this example…).
One of the allowed properties gave me a little headache though. That property was “NEWPAGE”.
Now, this is actually pretty easy in classic, just call CurrReport.NEWPAGE and your set to go. RDLC does not have such a property…
I started by creating an integer in classic increasing it as I run into the NEWPAGE property. Then passing it to RDLC allowed me to play around with it.
With it, I made a group with no header/footer, but with the property “New page after group”. This actually works pretty good, BUT also starts a new page ALWAYS after my table. For me, not really an issue, but the customer didn’t really like it, which is logical off course.
Some browsing around the internet and such showed me numerous options for a new page after a number of lines (also by using groups). But 1 post in particular spoke of adding a rectangle which also has a property “New page before/after rectangle”. In this case, the table was put inside the rectangle to keep it together on certain conditions. But gave me an idea none the less.
First I created a new row, and set the hidden property correctly to the “NEWPAGE” value. Then in 1 of the fields, I added a rectangle and set the property “New page after Rectangle”.
Well, It appears that either the property does not work inside a table or does not work at all. So I was off to a next solution again. Which, sadly, I didn’t find anymore.
Then I saw the rectangle looked like the body of the report itself containing a grid. I thought: what the hell, let’s just try some stuff. Inside the rectangle, I dropped another rectangle, reset the settings of the parent rectangle, and set the child rectangle property with the “new page after rectangle” Boolean. I saved my report and ran it. After the run, I had to look twice to make sure my eyes were not lying, but behold, the report was actually printing a page break whereI had wanted it to print it.
I really didn’t want to think about why it suddenly did print. I was just happy to deliver another finished report to my customer.
I literally spend a lot of time finding a solution on the internet. Where most sites told me it was impossible, 1 site offered me a step in the good direction. A bit of playing around, again, helped me to the final solution.
Maybe not a perfect solution, but at least workable and sort of clean.
Good luck to all other needing this kind of thing. I hope that I have been a bit helpful at least.
*UPDATE*: Please read this follow up post.