Friday, June 12, 2009

Alternating Row Background Color in Reports

Now lets see how to get alternating row background colors in Reports. This is one of the 1st typical report enhancement you might be doing once you started working on Reporting Services.  See the following report : 

report

This can be achieved very easily in SSRS with the help of IIF and RowNumber function for a simple report with no groupings.   You can use a background color expression as:

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

It becomes little complicated in cases of Matrix and when some groupings are involved.  In that case use following expression for the details row within a group:

= IIF(RunningValue(Fields!Some_Field.Value,Count,"Group_Name")
Mod 2, "White","Gainsboro")

Here instead of RowNumber function I have used he RunningValue function.  Just remember to replace Some_Field with actual column name and Group_Name with actual Group Name in your report.

No comments:

Post a Comment