Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Gridview and conditional formatting...

A girdview populated via a stored procedure has two columns.

CustomerName and PastDueYN


Question: How can I make CustomerName field shaded light blue for customers with PastDue = True (similar to the conditional formatting in MS Access).

Alos, is there a way to keep PastDueYN invisible?

Thank you,
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You would need to handle the RowDataBound event. In there you can check the values of the columns in the current row, and then apply a background colour based on the values.

You should be able to hide the column easily enough. How are you currently defining the columns for your GridView? Are you letting them be auto-generated?
Avatar of Mike Eghtebas

ASKER

Hi Carl,

Thank you your post. I located:
stackoverflow.com/questions/16799166/formatting-programmatically-changing-the-row-color-of-a-gridview-control

But it is in C#, I will try to get my control's name and attempt to apply to my project:
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        //in every row I would like to check the text of the second cell
        if (GridView1.Rows[i].Cells[1].Text == "C6N")
        {
            e.Row.BackColor = System.Drawing.Color.Red;

        }
    }

}

Open in new window


I will run by the code I come up with.

Mike
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial