To successfully create a client report definition (RDLC) report layout, you may need to add hidden fields to the body of the report. Typically, you add hidden fields to the table data region in the body section of the RDLC report layout. However, if there is more than one table data region in the report layout, then the header information is not displayed on pages that display the subsequent tables. Instead, it is only displayed on the page with the first table.

For reports such as document type reports that have multiple table data regions and require header information on each page, you must do the following steps:

An example of a report that has multiple table data regions and uses functions to save and get header data is report 206, Sales - Invoice, in the standard application.

For more information about using hidden fields for information that will be displayed in headers or footers, see Understanding Headers and Footers.

Before you begin this procedure, you must create a layout suggestion for the report. For more information, see How to: Create a Layout Suggestion.

To print header information on multiple pages

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Report, select a report that you want to modify, and then click Design.

  3. On the View menu, click Layout.

  4. In Microsoft Visual Studio, on the Report menu, click Report Properties.

  5. In the Report Properties window, click the Code tab, and then add the following code to the Custom code text box.

    NoteNote

    This example groups the data into four groups. You can modify the code if you need a different number of groups.

    NoteNote

    To view this code in a report in the standard application, see report 206, Sales - Invoice.

    Visual Basic  CopyCode imageCopy Code
    	Shared Data1 As Object
    	Shared Data2 As Object
    	Shared Data3 As Object
    	Shared Data4 As Object
    
    	Public Function GetData(ByVal Num As Integer, ByVal Group As Integer) as Object
    		If Group = 1 Then
    			Return Cstr(Choose(Num, Split(Cstr(Data1),Chr(177))))
    		End If
    
    		If Group = 2 Then
    			Return Cstr(Choose(Num, Split(Cstr(Data2),Chr(177))))
    		End If
    
    		If Group = 3 Then
    			Return Cstr(Choose(Num, Split(Cstr(Data3),Chr(177))))
    		End If
    
    		If Group = 4 Then
    			Return Cstr(Choose(Num, Split(Cstr(Data4),Chr(177))))
    		End If
    	End Function
    
    	Public Function SetData(ByVal NewData As Object, ByVal Group As Integer)
    		If Group = 1 and NewData > "" Then
    			Data1 = NewData
    		End If
    
    		If Group = 2 and NewData > "" Then
    			Data2 = NewData
    		End If
    
    		If Group = 3 and NewData > "" Then
    			Data3 = NewData
    		End If
    
    		If Group = 4 and NewData > "" Then
    			Data4 = NewData
    		End If
    	End Function
    
  6. In the Body of the report.rdlc file, create one or more hidden text boxes to get the header data. For example, in report 206, four text boxes, which correspond to the four groups in the code, were created. The following table shows the names and values of the four text boxes.

    Name Value

    CustAddr

    =Fields!CustAddr_1_.Value + Chr(177) + Fields!CustAddr_2_.Value + Chr(177)+ Fields!CustAddr_3_.Value + Chr(177)+ Fields!CustAddr_4_.Value + Chr(177)+ Fields!CustAddr_5_.Value+Chr(177)+ Fields!CustAddr_6_.Value + Chr(177)+ Fields!CustAddr_7_.Value+Chr(177)+ Fields!CustAddr_8_.Value

    CompanyAddr

    =Fields!CompanyAddr_1_.Value + Chr(177) + Fields!CompanyAddr_2_.Value + Chr(177)+ Fields!CompanyAddr_3_.Value + Chr(177)+ Fields!CompanyAddr_4_.Value + Chr(177)+ Fields!CompanyAddr_5_.Value + Chr(177)+ Fields!CompanyAddr_6_.Value

    CompanyInfo

    =Fields!CompanyInfo__Phone_No__Caption.Value + Chr(177) + Fields!CompanyInfo__Phone_No__.Value + Chr(177) + Fields!CompanyInfo__Fax_No__Caption.Value + Chr(177) + Fields!CompanyInfo__Fax_No__.Value + Chr(177)+ Fields!CompanyInfo__VAT_Registration_No__Caption.Value + Chr(177)+ Fields!CompanyInfo__VAT_Registration_No__.Value + Chr(177)+ Fields!CompanyInfo__Giro_No__Caption.Value + Chr(177)+ Fields!CompanyInfo__Giro_No__.Value + Chr(177)+ Fields!CompanyInfo__Bank_Name_Caption.Value + Chr(177)+ Fields!CompanyInfo__Bank_Name_.Value + Chr(177)+ Fields!CompanyInfo__Bank_Account_No__Caption.Value + Chr(177)+ Fields!CompanyInfo__Bank_Account_No__.Value

    SalesHdrInfo

    =Fields!Sales_Invoice_Header___Bill_to_Customer_No__Caption.Value + Chr(177) +Fields!Sales_Invoice_Header___Bill_to_Customer_No__.Value + Chr(177) + Fields!VATNoText.Value + Chr(177) + Fields!Sales_Invoice_Header___VAT_Registration_No__.Value + Chr(177) + Fields!ReferenceText.Value + Chr(177) + Fields!Sales_Invoice_Header___Your_Reference_.Value + Chr(177) + Fields!Invoice_No_Caption.Value + Chr(177) + Fields!Sales_Invoice_Header___No__.Value + Chr(177) + Fields!OrderNoText.Value + Chr(177) + Fields!Sales_Invoice_Header___Order_No__.Value + Chr(177) + Fields!Sales_Invoice_Header___Posting_Date_Caption.Value + Chr(177) + Fields!Sales_Invoice_Header___Posting_Date_.Value + Chr(177) + Fields!Sales_Invoice_Header___Due_Date_Caption.Value + Chr(177) + Fields!Sales_Invoice_Header___Due_Date_.Value + Chr(177) + Fields!Sales_Invoice_Header___Prices_Including_VAT_Caption.Value + Chr(177) + Cstr(Fields!PricesInclVAT_YesNo.Value) + Chr(177) + First(Fields!FORMAT__Sales_Invoice_Header___Document_Date__0_4_.Value) + Chr(177) + First(Fields!STRSUBSTNO_DocumentCaption_CopyText_.Value) + Chr(177) + Fields!SalesPersonText.Value + Chr(177) + Fields!SalesPurchPerson_Name.Value + Chr(177) + Fields!PageCaption.Value

    NoteNote

    Chr(177) is used here to separate the data in each group. When you call the GetData function, it splits the data in the group by using Chr(177) as a separator.

    For more information about creating hidden fields, see How to: Add and Identify Hidden Fields.

  7. In the Header of the report.rdlc file, create one or more hidden text boxes to save the data from the text boxes in the Body section. For example, in report 206, four text boxes with the following values were created:

    • =Code.SetData(ReportItems!CustAddr.Value,1)

    • =Code.SetData(ReportItems!CompanyAddr.Value,2)

    • =Code.SetData(ReportItems!CompanyInfo.Value,3)

    • =Code.SetData(ReportItems!SalesHdrInfo.Value,4)

    The first parameter in each SetData function call corresponds to the name of the text box in the Body section. The second parameter corresponds to the group number.

    For more information about creating hidden fields, see How to: Add and Identify Hidden Fields.

  8. In the Header of the report.rdlc file, create the text boxes for displaying data. The source expression for each text box must call the GetData function with the following two parameters:

    • The number of the variable in the group

    • The number of the group

    For example, Code.GetData(2,1) gets the second piece of data from group 1, which is CustAddr_2_.Value in the CustAddr group.

  9. Save and compile the report. For more information, see How to: Integrate Classic Client Report Designer and Visual Studio Report Designer.

See Also