New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial

Conditional Formatting

Updated on Oct 7, 2026

Formatting Data Based on a Column

The RadGrid object model and events support conditional formatting. To format data based on its column type, use the properties of the corresponding column. For example, GridBoundColumn.DataFormatString uses the standard .NET composite formatting rules, so {0:C} formats cell values as currency.

The example below shows how to use conditional formatting in a sample mailbox implementation. Selected Items and recently received mail are marked red:

Figure 1: Conditional formatting applied to grid items

Conditional formatting applied to grid items

Example: Formatting a cell when a data-bound value exceeds a threshold

C#
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    //Is it a GridDataItem
    if (e.Item is GridDataItem)
    {
        //Get the instance of the right type
        GridDataItem dataBoundItem = e.Item as GridDataItem;

        //Check the formatting condition
        if (int.Parse(dataBoundItem["Size"].Text) > 100)
        {
            dataBoundItem["Received"].ForeColor = Color.Red;
            dataBoundItem["Received"].Font.Bold = true;
            //Customize more...
        }
    }
}

When you apply a skin to the grid, the skin definitions can override custom row styles. To preserve custom formatting, define a CssClass for the corresponding row and apply the styles to that class.

The following example changes the appearance of items whose Country column contains Mexico:

Example: Defining a CSS class for matching rows

ASP.NET
<style type="text/css">
  .MyMexicoRowClass
  {
    background-color: aqua;
    font-size: 16px;
    font-family: Arial;
  }
</style>       

And in the code-behind:

Example: Formatting a row in the ItemDataBound event

C#
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        if (dataItem["Country"].Text == "Mexico")
            dataItem.CssClass = "MyMexicoRowClass";
    }
}

See Also