Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Calender Chaos

Calender Chaos

Scheduled Pinned Locked Moved Clever Code
helpquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reelix
    wrote on last edited by
    #1

    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); to DateTime 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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups