Friday, February 11, 2011

Alternating Background Colors in a Tablix Group

When alternating background colors in a group in a tablix, you cannot use the traditional formula for alternating rows (which would be something like: =iif(RowNumber(Nothing) Mod 2, "White", "#E5E5E5")  )

Instead you must use the following:

  1. To go the Code for the report (found in the Report Properties dialog)
  2. Add an even number function, and an internal variable to track the current row:
     Public _evenRow As Boolean  
    Public Function EvenRow() As Boolean
    _evenRow = Not _evenRow
    return _evenRow
    End Function

  3. Go to the “Group Properties” for the Row Group that you want to alternate, go to variables, and add a variable called EvenRow. The expression for this variable should be =Code.EvenRow().  This will be executed each time the group is created.
  4. Finally, in the background property for the group row, you can enter a modified version of the original expression: =IIF(Variables!EvenRow.Value=true,”Red”,”Green”)

No comments:

Post a Comment