my if statements dont work with my dates!! Bizzare

g_r_a_robinson

Well-known member
Joined
Jan 13, 2004
Messages
71
Hi all,

I have a ItemDataBound event that changes the colour of my row text if depending on the date IE one of my items in the list is overdue. It all works fine except for the actual if statement. The compiler keeps jumping to the second if statement even though the dates are equal (I can see them in the debugger, exactly the same).

<code>
if (TodaysDate > tmpDate)
</code>


Its an enigma. I thought maybe Ive done something wrong with the way in which Ive used the if statements and maybe it needs to be done differently withs dates. Any ideas would be most appreciated.

<code>
private void C1WebGrid1_ItemDataBound(object sender, C1.Web.C1WebGrid.C1ItemEventArgs e)
{
C1ListItemType lit = e.Item.ItemType;
String jobDueByDate;
DateTime TodaysDate = System.DateTime.Now;

if (lit == C1ListItemType.Item || lit == C1ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView) e.Item.DataItem;
jobDueByDate = drv[JobData.DUE_DATE_FIELD].ToString();

DateTime tmpDate = Convert.ToDateTime(jobDueByDate);

if (TodaysDate == tmpDate) // This job is to be done today
{
e.Item.BackColor = System.Drawing.Color.Blue;
}

if (TodaysDate > tmpDate) // This job is overdue
{
e.Item.ForeColor = System.Drawing.Color.Red;
}

}
}

</code>
 
Back
Top