Click here to Skip to main content
15,860,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

It depends which color you want to change. Here's a couple of examples in the code behind
C#
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
 
Share this answer
 
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
C#
gv.DataSource = data;
gv.DataBind();
gv.Rows[4].BackColor = System.Drawing.Color.Red;


C#
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;
               }
           }
       }
 
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