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. Web Development
  3. ASP.NET
  4. Setting a calendar's selected date

Setting a calendar's selected date

Scheduled Pinned Locked Moved ASP.NET
helpquestion
5 Posts 2 Posters 0 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.
  • W Offline
    W Offline
    waddie1
    wrote on last edited by
    #1

    This seems like something that should be easy but it just is not working. What I want to do is set the selected date of a calendar control programatically on the page load. I tried this and it did'nt work: myCalendar.SelectedDate = myDate myCalendar.VisibleDate = myDate The visible date is changed and the correct month is shown but the selected date is not highlighted like it is after you click on a date. Any suggestions on what the problem is? myDate is simply a date object. Thanks in advance.

    E 1 Reply Last reply
    0
    • W waddie1

      This seems like something that should be easy but it just is not working. What I want to do is set the selected date of a calendar control programatically on the page load. I tried this and it did'nt work: myCalendar.SelectedDate = myDate myCalendar.VisibleDate = myDate The visible date is changed and the correct month is shown but the selected date is not highlighted like it is after you click on a date. Any suggestions on what the problem is? myDate is simply a date object. Thanks in advance.

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      Are you sure myDate is a valid date? try setting the SelectedDate to DateTime.Now()

      W 1 Reply Last reply
      0
      • E ednrgc

        Are you sure myDate is a valid date? try setting the SelectedDate to DateTime.Now()

        W Offline
        W Offline
        waddie1
        wrote on last edited by
        #3

        Date.Now doesn't work but Date.Today does, the only difference is that date.today doesn't have hours, minutes and seconds. Now my date object does so I'm assuming that's the problem! Any idea's on how to force my date object into that format?

        E 1 Reply Last reply
        0
        • W waddie1

          Date.Now doesn't work but Date.Today does, the only difference is that date.today doesn't have hours, minutes and seconds. Now my date object does so I'm assuming that's the problem! Any idea's on how to force my date object into that format?

          E Offline
          E Offline
          ednrgc
          wrote on last edited by
          #4

          have you tried ToShortDateString()?

          W 1 Reply Last reply
          0
          • E ednrgc

            have you tried ToShortDateString()?

            W Offline
            W Offline
            waddie1
            wrote on last edited by
            #5

            :-D Cheers mate, that worked, didn't realise that it would take a string!

            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