This article briefly explains how to highlight the particular cell in a datagrid based on the cell value.
Here, in the following example a template column is used inside the datagrid.
Before datagrid control writes the cell value, it calls the public function GetColor and sets back ground color for the label.
<asp:TemplateColumnHeaderText="New Label%">
<ItemTemplate>
<asp:Labelrunat="server"BackColor='<%# GetColor(DataBinder.Eval(Container, "DataItem.ColName")) %>'Text='<%# DataBinder.Eval(Container, "DataItem.ColName
") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
public System.Drawing.Color GetColor(object result)
{
if(result!=DBNull.Value)
{
if(System.Convert.ToInt32(result)<=50)
{
return System.Drawing.Color.LightGreen;// "green";
}
else {
return System.Drawing.Color.LightPink;//"red";
}
}
else
{
return System.Drawing.Color.White;//"white";
}
}
If the cell value is less than or equal to 50, the back ground color would be green. If the value is greater than 50, the back ground color would be in red.