Link to home
Create AccountLog in
Avatar of Evan Cutler
Evan CutlerFlag for United States of America

asked on

Change row background color in gridview when value in column changes

I have a gridview with about seven columns.

It populates as a whole using the datasource/databind lines.
In column 2 "unitcode", it lists a identifier.

What I want, is when the unitcode changes from one row to the next, I want to change the background color of that row in the gridview.

I will NOT know how many rows from that particular return will fall in the same unitcode, and one return might not be exact of the next.  This will have to color on the fly.

Any ideas?
Avatar of larkydoo

One possibility is to create the gridview in Page_Init and then iterate through the rows in Page_Load, reading your value and toggling the row color based on the value.  This means you'll need to do the databind in code rather than as a sqldatasource object on the page.
Avatar of TSmooth

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Evan Cutler


That's a great start.
Is there a way to cycle through the
Create your own array/collection of color values you want to use, maintain a page level variable to hold the current value you're on, and then rotate through that array to pick the color.
Most thanks.