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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top