Groups | Blog | Home
all groups > sql server reporting services > may 2005 >

sql server reporting services : Alternating background color


G
5/27/2005 11:27:11 AM
Got a dataset that is used to populate a table. Want to alternate the
background color on every other row in the displayed detail group. Easy
enough right? Here's the catch: the output is grouped at display time. A
query output might be:

KEY Value1 Value2
A 0 1
A 1 0
B 5 0
C 3 0
C 0 7

etc...

The DISPLAY output is grouped on the KEY, and the two values are summed to
give me a display such as:

KEY Value1 Value2
A 1 1
B 5 0
C 3 7

Problem. When I use the standard "=iif(RowNumber(Nothing) MOD 2, "White",
"Grey")", it counts EVERY row returned from the original query, not the
grouped output, so I don't get a uniform white-grey-white pattern. Anyone
know a workaround for this?

TIA,

Brian

G
5/27/2005 12:12:07 PM
Ok, I found my workaround. Someone is bound to have this issue sometime in
the future, so I'll put the workaround here.

I created a little routine in the custom Code area of the report that simply
toggles and returns an integer value:

Dim Public bgColor As Integer = 0

Public Function alternateColor As Integer
If bgColor = 0
bgColor = 1
return bgColor
else
bgColor = 0
return bgColor
end if
End Function

When i put my method call in the background color on the entire table ROW,
the result was alternating COLUMN colors. This is because the method was
called for every cell (column) in the row. In order to get alternating ROW
color, I only called the alternateColor routine in the FIRST column in the
table row (iif(Code.alternateColor() = 0, "white", "grey")). Each subsequent
column in the row would simply check the "Code.bgColor" value for its
current value, and base its color on that (iif(Code.bgColor = 0, "white",
"grey")).

Maybe this will come in handy for someone else someday.....

Brian

[quoted text, click to view]

Carrie Taylor
6/2/2005 2:19:02 PM
Great solution, I've been playing around with RowNumber for ages - this is
much better!!!

Thanks Brian!!!


[quoted text, click to view]
AJ2005
6/17/2005 3:41:02 AM
This was just what i was looking for. My returned dataset sometimes Groups
so that rownumbers aren't in a consecutive order, giving some strange
alternate highlighting results using the conventional method. This should
work nicely, cheers

[quoted text, click to view]
Don H
6/28/2005 12:42:03 PM
This didn't work for me since I am setting a row to hidden based on a value
in that row. SQL RS thinks that row is still there and displays two back to
back colors instead of alternating the colors.

Any ideas?

Thanks,
Don

[quoted text, click to view]
Ben Shaffer
7/22/2008 7:32:47 AM
Thanks for this Brian. Even a couple of years later, your code piece has come in handy.

From http://www.developmentnow.com/g/115_2005_5_0_0_528879/Alternating-background-color.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button