Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Gridview as follows


ID Manager Empname Reprotingperson

1 Siva Ram Chandar
2 Kumar Sekar Suresh
3 Ram Mohan Vignesh
4 Raj Kannan Malar
5 Ravi Kumar Bala


from the above gridview i want to hightlight ID 1,3,4 rows in green color for that how can i do in asp.net using C#

In the gridview output as follows for the below row to be highlight in green color


1 Siva Ram Chandar
3 Ram Mohan Vignesh
4 Raj Kannan Malar

What I have tried:

  In Gridview as follows


  ID    Manager  Empname  Reprotingperson

  1      Siva    Ram        Chandar
  2      Kumar   Sekar      Suresh
  3      Ram     Mohan      Vignesh
  4      Raj     Kannan     Malar
  5      Ravi    Kumar      Bala


from the above gridview i want to hightlight ID 1,3,4 rows for that how can i do in asp.net using C#
Posted
Updated 29-May-17 21:52pm

1 solution

You can write the necessary logic in RowDataBound event to change row background color based on condition, something like following-
C#
protected void MyGridview_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int ID = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "ID"));

            if (ID == 1 OR ID == 3 OR ID == 4)
            {
                e.Row.Attributes["style"] = "background-color: #008000";
            }
        }        
    }


Hope, it helps :)
 
Share this answer
 
v2

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