Search code examples
sql-serverreporting-servicesssrs-2008-r2ssrs-tablix

SSRS - Repeat formatting on first row of each page


The requirement received for report in SSRS includes repeating formatting for the first row for 1 column on each page.

I already have Column Headers repeating on each page. This requirement is to repeat formatting of first data row (below column header) on each page.

Example:

Name   Money
ABC     $100
DEF      200

now Page 2 should look like

Name   Money
ABCD     $10
PQRS   10000

The $ sign should appear for first row of each page.

I was able to look at RowNumber() and do the format for first row

IIF(RowNumber("Table 1") = 1, "$" + Fields!Data.Value, Fields!Data.Value)

The first page has less number of rows than other pages, because it has a sub report taking up approximate half the page. So returning a fixed number of rows per page was not an option.

I am using SSRS 2008R2. Is there a way to achieve this?


Solution

  • Yes it's true you can only access Global!PageNumber on Header or Footer.

    Input this code in Report Properties code:

    dim c as integer = 1 
    dim last_c as integer = 0
    
    public function SetCurrentPage(i as integer) 
     c = i 
     return c 
    end function
    
    public function PageValue()
    
    if c <> last_c then     
     last_c = c     
     return "$" 
    else
     return "" 
    end if 
    end function
    

    On the header of your report insert a Textbox with the following expression:

    = code.SetCurrentPage(Globals!PageNumber)
    

    This way you can save you currentpage on the code behind.

    On the cell you want to add the "$" concatenate with

    =code.PageValue()
    

    Should only return $ on the first call for each page change.

    Hope it is a good example