Click here to Skip to main content
14,665,555 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi please haw can i change color for asp grid view row
if i need to change it for Row number 3 for example ?


please any idea :)
Posted
Updated 29-May-16 18:50pm
v2

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

Solution 1

It depends which color you want to change. Here's a couple of examples in the code behind
GridView1.Rows[0].BackColor = Color.Purple;
GridView1.Rows[1].ForeColor = Color.Plum;
GridView1.Rows[2].BorderColor = Color.Red;


The GridView1_DataBound event would be an appropriate place to put this
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

In addition to above solution.
the row color can also be changed using Style attributes
either after the calling the databind() method or inside the RowDatabound event
gv.DataSource = data;
gv.DataBind();
gv.Rows[4].BackColor = System.Drawing.Color.Red;


protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               if (e.Row.RowIndex == 3) // zero based index
               {
                   e.Row.Style.Add("background-color", "green");
                   // (or)
                   e.Row.BackColor = System.Drawing.Color.Green;
               }
           }
       }
   

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