Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to change the color of rows for the gridview based on the rows cell values.
Posted
Updated 18-Jan-10 7:22am
v2

code is below,

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    if ((e.Row.DataItem("Status").ToString() == "No"))
    {
      e.Row.BackColor = System.Drawing.Drawing.Color.Red;
    }
    else if ((e.Row.DataItem("Status").ToString() == "Yes"))
    {
      e.Row.BackColor = System.Drawing.Drawing.Color.Green;
    }
  }
} 
 
Share this answer
 
In the ItemDataBound event of the datagrid, you have access to rows of the grid. You can set your desired style at this point for display.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900