WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 529 reviews for our classroom and online training
Two ways to create alternating colours in SSRS
Part three 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
  3. Alternate Colours using a Custom Assembly (this blog)

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 a Custom Assembly

This blog page shows how to apply alternate colours to the rows of a table by using a custom assembly written in either VB or C# (both are shown).

To keep the length of this blog manageable - and to avoid reinventing wheels - I'm assuming that you've read my previous lengthly tutorial on creating custom assemblies for SSRS.

The Method Used

The approach I'll take (it's the same for VB and C#) is to create a method/function which takes 3 arguments:

Argument How it's used
OddColour The colour to apply for odd rows
EvenColour The colour to apply for even rows
IfToggle Whether to change colour or not

Let's call this function ChangeColour.  Then for our example we could call the function as follows:

First column function call

The numbered steps are shown below.


We'll call the function as follows:

  1. For the first column, ChangeColour("PaleTurquoise","Pink",True)
  2. For all other columns, ChangeColour("PaleTurquoise","Pink",False)

This will have the effect of switching colours whenever a new row starts.

The Functions in VB and C#

Here is the code we'll use for C#:

private static bool IfOddRow;


public static string ChangeColour(

string OddColour,

string EvenColour,

bool IfToggle



// swap from odd to even or back, if

// reqd (for columns>1, won't be)

if (IfToggle) { IfOddRow = !IfOddRow; }

// return the odd or even row colour

if (IfOddRow)


return OddColour;




return EvenColour;



And here's the VB equivalent function:

Private Shared IfOddRow As Boolean


Shared Function ChangeColour(

OddColour As String,

EvenColour As String,

IfToggle As Boolean

) As String


'swap from odd to even or back again, if

'reqd (for all but 1st column, won't be)

If IfToggle Then IfOddRow = Not IfOddRow


'return the odd or even row colour

If IfOddRow Then

Return OddColour


Return EvenColour

End If


End Function

The idea in both cases is to return either the first colour or the second colour, depending on the value of the IfOddRow flag.

Setting the Cells' BackgroundColor Property

When you've created your method or function, built the class library, copied over the DLL and referenced it in your report (as described in my previous blog on custom assemblies) you can use the code in your report.  First select the left-hand cell of your table:

Left cell of table

Select the first column's cell.


Use the expression builder to set this cell's background colour to be an expression like this:

Background colour expression

The first cell of each row will trigger a colour change.

Note that you can use either standard colour names or hexadecimal RGB colour codes.

Now select the other cells in the row:

All but first column cell

Select all of the other cells in the row.


You can now set their background colour to be a call to your function which doesn't change the colour:

Expression for background colour

The second and subsequent cells use the same colour as the first one.

For each expression:

  • FunctionsC is the name of the class library project;
  • SampleClass is the name of a class within this; and
  • ChangeColour is the name of the method called.

(This assumes we've used C#; for VB it would be exactly the same).  The effect might have been pleasing if I'd chosen better colours:

Alternate rows

Whenever a new row starts, the colour changes.


A Variation on the Theme

You can create a chessboard effect by setting the background colour of the selected cells to be:


Since the colour will now change whenever a new cell is created, you'll get this effect:

Chessboard effect

Every new cell has a different colour to its predecessor.


You now have complete control over how your cells are coloured!

This blog has 0 threads Add post