Click here to Skip to main content
14,669,305 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 2

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;
    }
  }
} 
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100