How to format radgrid cell programmatically

dotnet_learner picture dotnet_learner · Aug 26, 2009 · Viewed 30.5k times · Source

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?

Answer

live-love picture live-love · Jun 20, 2011
 protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
            {
                TableCell cell = item["Column"];
                cell.BackColor = Color.PeachPuff;
            }
        }
    }