g_r_a_robinson Posted February 4, 2004 Posted February 4, 2004 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 I've done something wrong with the way in which I've 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> Quote
Administrators PlausiblyDamp Posted February 4, 2004 Administrators Posted February 4, 2004 Try System.DateTime.Today instead of DateTime.Now - could be due to the time portion not being equal. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.