Alternating Row Colours in Reporting Services (SSRS)

One of the most frequently asked questions in Reporting Services is “How do I alternate my row colours?”.   There are ample articles and solutions out there, in Australia we call these “Commodores”, in Virginia you probably call them “RAM 1500’s” and in Seattle  “Lincolns”, so I am going to add one more “Lincoln” but with a more hands on approach.

Firstly, you need to check out Powerview to see how much easier it is to apply professional looking visuals to your report.   For SSRS Report Designer and Report Builder tools though, unfortunately you won’t find a formatting widget on the toolbar to do this.  So lets get started on the procedure by utilising Expressions for our background color property.

If you have a standard table with no grouping, select each column in your detail row (select Ctrl and click each cell as opposed to just selecting the row), and in the Background color property, adapt the following expression…

IIF(RowNumber(Nothing) Mod 2, "Gainsboro", "White")

If you have a table with any weird groupings, or you have a Matrix, you are really better off utilising a nice piece of code from WROX

First add the following function to your report (go to your report properties and find the Code section) …

Private bOddRow As Boolean
' -- Display green-bar type color banding in detail rows
' -- Call from BackGroundColor property of all detail row textboxes
' -- Set Toggle True for first item, False for others.
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Return EvenColor
End If
End Function

Then click on each cell in your detail row…for the very first leftmost cell enter the following code in the expression for the cell’s Background Color property …

=Code.AlternateColor("Gainsboro", "White", True)

For all other cells use this background property expression  instead.

=Code.AlternateColor("Gainsboro", "White", False)

Thanks to the following references.

BrianMcDonald and WROX.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s