Two ways to create alternating colours in SSRS
Part two of a three-part series of blogs

A common requirement for Reporting Services reports is to colour alternate rows. This blog gives two approaches, one of which uses custom assemblies.

  1. Alternating Colours in Reporting Services Tables
  2. Alternate Colours using Conditional Formatting (this blog)
  3. Alternate Colours using a Custom Assembly

Posted by Andy Brown on 03 August 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Alternate Colours using Conditional Formatting

The simplest (and most common way) to colour rows conditionally is shown below.

Creating Alternate Colours using the BackgroundColor Property

A simple way to create an alternate colour effect for a report is to set the background colour for table cells to be the following:

IF the row number is divisible by 2 with a remainder of 1, then colour the row blue; otherwise, colour it pink.

To do this, first select the cells that you want to conditionally format:

Selecting cells to format

Use the SHIFT key (easier) or mouse to select all of the cells in the row you want to format.

 

Now find and change the cells' BackgroundColor property:

BackgroundColor expression

Find the BackgroundColor property of the cells, and choose to create an expression for it.

 

Use the expression builder to create an expression for the background colour like this:

Background colour expression

Set the background colour differently according to the whether the number of the row is odd or even.

The RowNumber(Nothing) function gives the row number of the current row within the scope of the table.

When you preview your report, the row colour will alternate:

Alternating row colour

Odd and even rows are coloured differently.

 

Problems with this Approach

In most cases the above approach will work OK, but it breaks down for some grouped reports and it's not very flexible.  An alternative - but more complicated way - is to use a custom assembly, as shown in the final part of this blog. 

  1. Alternating Colours in Reporting Services Tables
  2. Alternate Colours using Conditional Formatting (this blog)
  3. Alternate Colours using a Custom Assembly
This blog has 0 threads Add post