I have to format (backcolor, forecolor, font style) a radgrid's cells depending on the value of the cell.
For example If the value is negative set the fore color of that cell as red.
Can any one please tell me how this can be achieved?
I have to format (backcolor, forecolor, font style) a radgrid's cells depending on the value of the cell.
For example If the value is negative set the fore color of that cell as red.
Can any one please tell me how this can be achieved?
and the line onItemDataBound="Data_OnitemDataBound" to your radGrid declaration in your aspx page.
Then add this to your code behind. the number in the Cells[] is the index of the column you want to modify or validate against.
protected void Data_OnItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; if (Convert.ToDecimal(item.Cells[3].Text) < 0) { item.Cells[3].ForeColor = System.Drawing.Color.Red; } } }
Thanks Jason. It worked. I placed the code in the RadGrid1_ItemDataBound event.