We are all learning new things about RDLC report design and we know that still there are lot of things to learn about, here are the things I’m sharing which I learned.
1. How to make page Header and Footer as dynamic.
2. How to print page Footer on last page only.
3. How to remove empty/blank rows in grouping.
4. How to print TransHeader and TransFooter in RDLC reports.
5. How to print Header and Details in different pages.
6. Things help to faster the report design.
1. How to make page Header and Footer as dynamic.
You may thinking about what are dynamic page header and footer, and what difference with static. Here I will explain the difference between dynamic and static page headers and footers are, and how to make static headers and footers as dynamic.
A. What are dynamic page header and footer?
Page headers or footers are usually static by default, it means you can’t print different or unique details/information on each page, if you wish to change or update details/information on each page you need to make the page footer or header as dynamic.
For example: Usually headers are used to print date, page number, name of the company, Logo, and so on. These texts or images are constant as they print same on every page, so we can call it as static header. The dynamic page header or footer prints different data on every page, for example: Sales – Invoice (document) report page header displays sales invoice header and body of the report displays corresponding sales lines and Page footer displays total. I will explain how to achieve this and what the benefits are, in next sections.
B. How to make static page header or footer into dynamic?
There are two or more ways to make static page headers or footers into dynamic, below are the fewlisted among.
i. You can write simple code in VB.
ii. You can use references to fields in the body part of the report.
1) How to use/write simple code in VB:
In below screenshot you can see that there is a simple code which can be used to achieve dynamic page header and footer.
To add code to the report, click the Report menu on the menu bar, then choose “Report Properties” on the menu list, then it opens “Report Properties” window where click the Code menu item on the window, which has shown in below screenshot.
Figure 1: Shows GetData and SetData methods.
The syntax is simple that we can to understand and can also easily write/read. The GetData function gets the value and store it in a variable, where SetData function sets the stored value to a variable. I explain more detail about Cstr and Split function shown on the code above later in section.
Now I explain how to use this code. This simple code is used to get the value from a row/column displays the data on body and to set and displays the same value on the page header or footer to make them as dynamic.
The following are the steps which explain how to use this code to make the page header and footer as dynamic.
For example: If you wish to display the value “No.” from Sales Header table,
1. First we should add the field in data item columns in the report designer, which as shown in the below figure 2.
Figure2: Shows Dataitem columns.
2. After we add a field or text box (Sales Invoice Header) “No.” in the Tablix control, set or pass the value, for instance. The following steps shows how to pass or set the value.
a. To set or pass the value, select any Text Box (Set or Pass Value Here) as shown in below figure 3, for instance.
b. After select the Format property of the text box and click the Expression field as shown in below figure 4.
Figure 4: Shows Property window of the TextBox (Set or Pass Value).
c. After system opens the below expression window, where we can write simple code to pass the value of required field. As I explained previously, SetData and GetData functions, here we are using SetData function to pass the data/value.
The SetData function passes two values, firstly CStr function, which is used convert data into string type and secondly the value 1, it indicates the group this value belongs, it is not necessarily required, but it helps to distinguish the between different set of values for set and get.
Figure 5: Shows Expression window, where we pass value.
d. If you look at the figure 1, you can see the function stores the value received in a variable, the value can be get by using GetData function. The GetData function receives two parameters, first is which value, for example: first, second, third and so on, we can concatenate any number of values while passing to the SetData function, Sales Invoice Header table’s “No.”, Name, and so on, for instance. Thus we must mention which data/value as first parameter and second parameter is about what group as I mentioned earlier.
The Choose function is used to select the certain data/value based on the number passed as which field and Split is used split the string which was concatenated with two or date fields or values while passing through SetData function. And Chr(177) function is field or value delimiter or separator. As shown in below figure 6.
Figure 6: Shows Code of the GetData function.
e. Below figure shows how to get the value passed through SetData function, call GetData function as shown below. To know more about GetData function look at the previous point.
Figure 7: Shows GetData function code.
f. Save and Run the report.
g. Following figure shows output, where page header has been updated with the corresponding values at the report body.
Figure 8: Output of the first record, where 103002 Sales Invoice No. is as same as report body.
Figure 9: Output of the second record, where 103003 Sales Invoice No. is as ame as report body.
As I explained earlier there is one more method to make the page header or footer as dynamic, here it is:
2) You can use references to fields in the body part of the report.
You access the value of the control/field in the body of the report by writing an expression or code.
Below figure shows the expression is used to get the Sales invoice number from [No_SalesInvoiceHeader] control on the body of the report as shown in below figure.
The syntax is “ReportItems!ControlName.Value, where ControlName is “No_SalesInvoiceHeader”.
Figure 10: Shows how to get value from a control in the body of the report.
I will cover remaining points such as How to print page Footer on last page only, How to remove empty/blank rows in grouping and so on my next blogs.
If you wish to discuss regarding this RDLC Report Design blog, please feel free to drop me an email to dileepa.b@ecanarys.com.