Saturday, November 13, 2010

Row Background Color based on the Gridview Rowitem value

 Using below code We can set the background color of row based on the value in Gridview rowitem.

protected void gvMsg_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

// determine the value of the UnitsInStock field

string Category =Convert.ToString(DataBinder.Eval(e.Row.DataItem,"ColumnName"));

if (Category.ToString() == "Value")

// color the background of the row yellow

e.Row.BackColor = Color.FromName("#8FB3E3");

}