On some reports, you may want to group sets of data together and reset the page number after each group. For example, in the standard application, report 206, Sales Invoice, displays sales invoices that are grouped by sales invoice number. To reset the page number to 1 for each group of data, you must modify code on the client report definition (RDLC) report layout.

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 reset page numbers

  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, in the Report.rdlc file, on the Report menu, select Report Properties.

  5. In the Report Properties window, select the Code tab.

  6. Add the following code in the Custom code text box:

    Visual Basic  CopyCode imageCopy Code
    REM Reset Page Number:
    	Shared offset As Integer
    	Shared newPage As Object
    	Shared currentgroup1 As Object
    	Shared currentgroup2 As Object
    	Shared currentgroup3 As Object
    	Public Function GetGroupPageNumber(ByVal NewPage As Boolean, ByVal pagenumber As Integer) As Object
    		If NewPage Then
    			offset = pagenumber - 1
    		End If
    		Return pagenumber - offset
    	End Function
    	Public Function IsNewPage(ByVal group1 As Object, ByVal group2 As Object, ByVal group3 As Object) As Boolean
    		newPage = False
    		If Not (group1 = currentgroup1) Then
    			newPage = True
    			currentgroup1 = group1
    			If Not (group2 = currentgroup2) Then
    				newPage = True
    				currentgroup2 = group2
    				If Not (group3 = currentgroup3) Then
    					newPage = True
    					currentgroup3 = group3
    				End If
    			End If
    		End If
    		Return newPage
    	End Function

    This code is also available in report 206, Sales Invoice.

  7. Click OK.

  8. In Visual Studio, in the Report.rdlc file, right-click the text box in the header that displays the page number, and then select Expression.

  9. In the Expression window, enter the following expression.

      CopyCode imageCopy Code

    The NewPage.Value parameter is the value of the NewPage text box, which you create in step 8.

  10. Click OK.

  11. In the Body section of the layout, create a new text box called NewPage.

  12. Right-click the NewPage text box that you created in step 8 and then select Properties.

  13. In the Properties window, on the General tab, enter the following in the Value field.

      CopyCode imageCopy Code
    =Code.IsNewPage(Fields!<grouping field1>[,<grouping field2>,<grouping field3>])

    For example, if you are grouping by document type, then grouping field1 would be Document_Type.Value.


    If you want to use more than three groupings, you can modify the code in the IsNewPage function. If you want to use fewer than three groupings, you can either modify the code in the IsNewPage function or use a static value for one or more of the parameters.

  14. Click OK.

See Also