datagrid cell color changed 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!!