Calender Chaos
-
I had some code I was (attempting) to optimise, and came across a weird problem... I have a button, and 2 Calender Controls Here's the code
protected void Button1_Click(object sender, EventArgs e) { string date = "2008/03/27 12:36:00 PM"; int year = Convert.ToInt32(date.Substring(0, 4)); int month = Convert.ToInt32(date.Substring(5, 2)); int day = Convert.ToInt32(date.Substring(8, 2)); int hour = Convert.ToInt32(date.Substring(11, 2)); int minute = Convert.ToInt32(date.Substring(14, 2)); //Compare the following 2... // Original Code DateTime dt1 = new DateTime(year, month, day); Calendar1.SelectedDate = dt1; // My new code (Hopefully removing all the above string manipulation) DateTime dt2 = Convert.ToDateTime(date); Calendar2.SelectedDate = dt2; }
Looks the same, correct? That's what I thought... The Problem - After the Button is clicked, the 1st Calender has it's date selected, and the second one doesn't... Now, the thing is, if you change:DateTime dt1 = new DateTime(year, month, day);
toDateTime dt1 = new DateTime(year, month, day, hour, minute, 0);
then the first Calender "Breaks", and doesnt select the date... After playing with it about it for around 2 hours with no success whatsoever, I jumped across to the codeproject forums... After abit of posting, I found the bug...Calendar2.SelectedDate = dt2
->Calendar2.SelectedDate = dt2.Date;
Both compile, only bottom one selects... X| P.S - Many thanks to Jesse Squire for the assistance!!!! :-D