views:

2007

answers:

1

I am using the below code to dynamically change the text, but I also need to change the color from black to red of the entire row in SSRS, using VB.NET. However, row.Cells.Style.ForeColor = System.Drawing.Color.Red does not work. Any ideas on how to dynamically change text color in a particular row?

Public Shared Function ChangeWord(ByVal s As String) As String
    Dim strBuilder As New System.Text.StringBuilder(s)
    If s.Contains("Others") Then
        strBuilder.Replace("Others", "Others FIG NOT INCL")
        Return strBuilder.ToString()
    Else : Return s
    End If
End Function

Public Shared Function ExcludeOthers(ByVal rowDesc As String, ByVal rowVal As Integer) As Integer
    If rowDesc.Contains("Others") Then
        rowVal = 0
        Return rowVal
    Else
        Return rowVal
    End If
End Function
+3  A: 

My understanding of your question is that you want to conditionally set the text colour of a row to red if a description field in the report contains the value "Others"

You don't need any VB.Net code to do this.

In the Layout tab of the report designer, select the row you want to format conditionally by clicking the box outside the left-hand edge of the leftmost cell.

On the properties of this row, set the value of the "Color" attribute, select "Expression..." from the drop-down.

In the Expression editor, enter the following code

=iif(Fields!~MyColumnName~.Value.ToString().Contains("Others") = True,"Red","Black")

You'll need to change ~MyColumnName~ to the actual name of the column in your dataset.

Ed Harper
Dear Ed, I do not know how to thank you. Thanx a million for your help!
Greg