26

How do I give row color and alternate row color for a Table in RDLC report? When I googled I found most of the result says something like = iif(RowNumber(Nothing) mod 2, "Red", "White") OK! But where should I place this stuff? Any help will be appreciated.

5 Answers 5

34

Very easy! :-)

In your report designer surface, you need to select the data row that contains your data - something like this:

enter image description here

When you look at the Properties box for that data row, you will see a property call BackgroundColor - open the dropdown, and you'll see all the usual colors - but also a menu item at the bottom called Expression...:

enter image description here

When you select that item, a dialog box will open that allows you to insert an expression to determine the background color for that row - that's where you need to put that expression that you have - and that's all there is!

3
  • This is specific to SSRS 2008|R2 Commented Jun 28, 2011 at 9:19
  • 1
    @Adolf Garlic: not that I am aware of - I used this approach in SSRS 2008 for sure (possibly even 2005), too
    – marc_s
    Commented Jun 28, 2011 at 10:23
  • Awesome! this works in VS2010 RLDCs when the old way (The background color tool bar button-> expression) does not. Commented Jun 27, 2012 at 20:53
25

If you don't want to add a RowNumber field to your dataset, just use the built in function RowNumber(ScopeName as String). I commonly use the name of the DataSet as parameter:

= IIF(RowNumber("CarsWithNoMakeDataSet") Mod 2 = 0, "LightGrey", "Transparent")

You can find this function at the Expression dialog, Category "Common Functions", Subcategory "Miscellaneous"

As the ScopeName parameter it is possible to use the name of a Group or Data Region. Please find more here.

Hope it helps,

0
19

The expression definition to alternate the row color is:

=iif(Fields!RowNumber.Value Mod 2 = 0,"LightGrey","White")

This sample assumes you have a field RowNumber in your dataset.

2
  • 1
    What about if I want to use a different font for a particular RowNumber?
    – lionheart
    Commented May 1, 2013 at 1:19
  • 1
    To use a different font you have to put an expression in the --"FontFamily" property the instead of Background Color property: =iif(Fields!RowNumber.Value Mod 2 = 0,"Arial","Tahoma")
    – codea
    Commented May 2, 2013 at 8:35
1

You can use group data region instead of dataset name.

Eg: = IIF(RowNumber("MonthOfYearId") Mod 2 = 0, "LightSteelBlue", "No Color")

0

Note that using dynamic expression can affect the time required to export a report. For a report with 5K of rows, the time increase may reach 2-3 minutes.

This is the expression I had to remove from one of my reports to make the export time acceptable: =iif(RowNumber(Nothing) Mod 2, "White", "#e6eefc")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.