Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a grid veiew which has two columns - name and salary of person .Now i want to highlight particular cell where persons salary exceeds a particular amount .How to implement it ?
Posted

You can use GridView's RowDataBound Event like this:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow )
            {
              
                double salary=0.0;
               salary= double.parse(e.Row.Cells[1].Text;
                if (salary>=5000)
                {
                    //highlight row or cell here
                    e.Row.Cells[1].BackColor=System.Drawing.Color.Red ;
                    //e.Row.BackColor=System.Drawing.Color.Red ;
                 
                }
            }
        }
 
Share this answer
 
use the OnRowDataBound event. In that event you still have access to the data and you can check the value of salary. In that case the row or cell Color can be changed.
 
Share this answer
 
Comments
Pravin Patil, Mumbai 13-Sep-11 2:57am    
Good answer.
My 5...
 
Share this answer
 
Comments
Pravin Patil, Mumbai 13-Sep-11 2:57am    
Nice links...
My 5
Prerak Patel 13-Sep-11 3:19am    
Thanks Pravin
Are you retrieve data from a database (SQL) ? If so you can do this with the query.

Check the condition and wrap it with a CSS class.
 
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