You're pretty close... If you would like to change forecolor for specific column, for example: "Rate", check this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblRate = e.Row.FindControl("lblRate") as Label;
Double rate = Convert.ToDouble(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Rate")));
if (rate <= .0)
{
DataControlFieldCell d = lblRate.Parent as DataControlFieldCell;
d.BackColor = System.Drawing.Color.Red;
e.Row.BackColor = System.Drawing.Color.LightBlue;
lblRate.ForeColor = System.Drawing.Color.White;
}
}
}
For further details, please see:
How to make a Gridview Row Color/ Cell Color/ Text Color « Devils Work[
^]
You might be interested in some sort of validation too:
Tutorial 19: Adding Validation Controls to the Editing and Inserting Interfaces[
^]