New to Telerik Reporting? Download free 30-day trial

Conditional Formatting

You can design a report so that different styles are applied to items based on the data in the report. For example, you can display negative numbers in red or change the background colors on a table cell.

To make styles conditional, use an expression instead of a static value for the style properties of the report item. The two examples below demonstrate how to make a Text box render negative values in red for a field called Profit. You can achieve this with the Conditional Formatting Editor in Report Designer or by using Bindings.

Using Conditional Formatting Editor

  1. In Report Designer, right-click on a Text Box report item.

  2. In the context menu, select Conditional Formating.

  3. The Conditional Formatting Rules... dialog appears on the screen.

  4. Enter the conditional expression:

    =Fields.Profit
    
  5. Enter the operator:

    <
    
  6. Enter the value expression:

    =0
    
  7. In the Edit Style dialog select Red color for the Background.

Using Bindings

  1. To use Bindings, we need to implement a helper User Function:

    public static Color ColorFromName(string colorName)
    {
    if (!string.IsNullOrEmpty(colorName))
    {
        return Color.FromName(colorName);
    }
    return Color.Transparent;
    }
    
    Public Shared Function ColorFromName(ByVal colorName As String) As Color
    If Not String.IsNullOrEmpty(colorName) Then
        Return Color.FromName(colorName)
    End If
    Return Color.Transparent
    End Function
    
  2. In the Bindings Editor select the Style.BackGroundColor property.

  3. Enter the next expression:

    =Iif(Fields.Profit < 0, ColorFromName("Red"), ColorFromName("White"))
    

See Also

In this article