INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Controls

How can I carry out Conditional formating on a Gridview ? by Chance1234
Posted: 19 Jun 07

Say in your gridview you have the following data ;

Month, Target, Result
June, 0.23, 0.24
July, 0.17, 0.15
Sept, 0.25, 0.37

In your Gridview, you want to highlight the cell when the Months result is less than the Target.

What you want to do is the following.

On the RowDataBound event of the gridview add the following code.

CODE

//First check to see that we are on a data row
  if (e.Row.RowType == DataControlRowType.DataRow)
            {
//now convert the text value to a double (use int32 for whole numbers)
                if (Double.Parse(e.Row.Cells[2].Text) < Double.Parse(e.Row.Cells[1].Text))
                {
//set the background to red
                    e.Row.Cells[5].Style.Add("background-color", "red");
//you can also access other properties such as font from here, as below
                    e.Row.Cells[5].Font.Bold = true;

                }
               
            }

Back to Microsoft: ASP.NET FAQ Index
Back to Microsoft: ASP.NET Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close