How to change row color in DataGrid?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I conditionally change the color of a row in DataGrid? I have a
column named “MonthClosed†in my DataGrid. If the value of in this column of
a row is True then I want to set the color of entire row to Green otherwise
as Blue.

Thanx
 
You should be able to change the color of the row in the OnItemDataBound event.

Example code for this event:

CheckBox box;
box = (CheckBox)(e.Item.Cells[3].Controls[0]);
if (box.Checked == true) e.Item.BackColor = Color.Green;

This assumes that the MonthChanged column is in #3.

Sujit D'Mello
 
Back
Top