Changing text color of a data grid cell

I want conditionally change the text color and background color for all columns of a row.
I was setting the CellRender property and defined in the @code block the following method:

void CellRender(Radzen.CellRenderEventArgs<EventData> args)
        if (!args.Data.IsAcknowledged)
            args.Attributes.Add("style", "background-color: red; color: white;");

On execution, only the background color is changed, but not the text color of the cell.

How can I solve this problem ?

The data grid cell color is set from the CSS theme and takes precedence. You can however style it as in our online demo:

<RadzenGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity">
   <Template Context="data">
   @if (data.Quantity > 20)
       <span style='color:white'>@data.Quantity</span>
       <span style='color:black'>@data.Quantity</span>

Thx, I was aware of this, but I want to prevent adding a template for each column

args.Attributes.Add("class", "white-text");

td.white-text span.ui-cell-data {
color: white !important;

works just fine for color :slight_smile:


Hi korchev,

When I implemented your solution, I lost the string format. The FormatString value I set on the parent tag doesn't affect the output anymore.

Do you have any solution to this?

This is working though:

Hey @Adem,

In templates you should apply desired format yourself.

1 Like