Search code examples
ssrs-2012

SSRS expression change text color


I have text box with expression (see image).
All text will get 'lightcoaral' color.
I would like to change '|' become black color. Can you shoe me how to modify the expression.
Thank you.

enter image description here


Solution

  • You don't give a ton of details about the issue at hand, but to do this, you need to create a placeholder and change the markup type to "Interpret HTML tags as style". It's possible you've already done this, considering the use of HTML tags. From there the expression should be:

    = "<font color = 'black' size = '1'>" & " | " 
    & "</font><font color = 'lightcoral' size = '1'>" 
    & IIF(Trim(First(Fields!ID.Value, "DataSet2")) = "", "None", First(Fields!ID.Value, "DataSet2"))  
    & "</font>"
    

    It isn't clear if there is meant to be other text before the " | " but you simply need an additional <font> tag for each segment of text you'd like to color.

    So based on the comments, you need another block in front of the " | " like this:

    = "<font color = 'lightcoral' size = '1'>"
    & IIF(Trim(First(Fields!ID.Value, "DataSet2")) = "", "None", First(Fields!ID.Value, "DataSet2"))
    & "</font><font color = 'black' size = '1'>" & " | " 
    & "</font><font color = 'lightcoral' size = '1'>" 
    & IIF(Trim(First(Fields!ID.Value, "DataSet2")) = "", "None", First(Fields!ID.Value, "DataSet2"))  
    & "</font>"
    

    And you'll just need to modify the field from the first statement to what you'll need before the " | ".

    For reference, the above expressions show as this image in my environment(Left textbox is first expression, right is second):

    Left textbox is first expression, right is second

    Another alternative would be to set the entire textbox font color property to lightcoral and simply use the expression:

    "<font color = 'black' size = '1'>" & " | " & "</font>" 
    & IIF(Trim(First(Fields!ID.Value, "DataSet2")) = "", "None", First(Fields!ID.Value, "DataSet2"))