Datagrid cell color change based on datetime
I have a bound datagrid on an asp.net page. One column is filled with a DateDue, datetime.
I am trying to check and if the date is less than a week out, I need to make the cell or text Red.
This is what I've attempted and, of course, it doesn't work:
private void dgProjects_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
if(drv.Row.ItemArray[6] <= DateTime.Now )//and somehow add 7 days to this date)
{
e.Item.Cells[3].BackColor = Color.Red;
}
}
}
Thanks - I appreciate any help!!

rulec444106 reputationPosted Sep 28, 2004, 12:18 PM EDT
sathyaselvi_v10 reputationPosted Oct 5, 2004, 4:14 AM EDT
"); Response.Write(past+"
"); if(DateTime.Compare(now,past)==-1) Response.Write("Not Equal"); else Response.Write("Equal");
jshepler59 reputationPosted Oct 6, 2004, 2:34 PM EDT
rulec444106 reputationPosted Oct 12, 2004, 1:05 PM EDT
fadil197777 reputationPosted Oct 13, 2004, 4:17 AM EDT
rulec444106 reputationPosted Oct 13, 2004, 7:19 AM EDT