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!!
rulec444Posted Oct 13, 2004, 11:19 AM
fadil1977Posted Oct 13, 2004, 8:17 AM
rulec444Posted Oct 12, 2004, 5:05 PM
jsheplerPosted Oct 6, 2004, 6:34 PM
sathyaselvi_vPosted Oct 5, 2004, 8:14 AM
"); Response.Write(past+"
"); if(DateTime.Compare(now,past)==-1) Response.Write("Not Equal"); else Response.Write("Equal");
rulec444Posted Sep 28, 2004, 4:18 PM