SSRS change the color of alternate row based on database values

Solution:

To change color of alternate row, based on dataset value:

Function:

Private _orgCount As Integer = 0

Private CurRowNumber as Integer = 0

Private ColorValue as String = “”

Function GetRowColor(ByVal previousOrgID As Integer, ByVal currentOrgID As Integer, MyRowNumber as Integer) As String

‘Check if this is a new row number…

If MyRowNumber <> CurRowNumber then

CurRowNumber = CurRowNumber  + 1 ‘New row, so increment counter

If previousOrgID = currentOrgID Then

‘ Do nothing

Else

_orgCount = _orgCount + 1

End If

If _orgCount Mod 2 = 0 Then

ColorValue = “White”

Else

ColorValue = “Lavender”

End If

End If

Return ColorValue ‘Always return a value (for columns other than the first one)

Write this as Expression in Row’s backgorund color property:

=Code.GetRowColor(Previous(Fields!org_id.Value), Fields!org_id.Value, RowNumber(Nothing))

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s