gridview change cell backcolor based on variable
Posted on 2008-10-26
I have a gridview in C# (2005/.Net2.0) and I would like to change the bg color of a cell (or the text color I really don't care at this point) based on the value of a variable.
If the cell falls in the 6th column, called "Age", and the value of a particular cell is above the average age ( double varAvgAge) then I would like the bg color to be Red. If the value of a cell is less than the average age, I would like the color to be green.
here is the code for my gridview:
string filePath = Server.MapPath("xml/averages.xml");
usersDataSet = new DataSet();
//Read the contents of the XML file into the DataSet
GridView1.DataSource = usersDataSet.Tables.DefaultView;
thanks in advance