calendar control : how to retrieve the "shown" month and year

Discussion in 'ASP .Net' started by tfsmag, Jun 17, 2005.

  1. tfsmag

    tfsmag Guest

    i need to create a date range based on the current "shown" month on a
    calendar control to query a database and populate a datagrid based on
    that date range.

    how can i retrieve the "shown" month and year from the calendar control
    to create this range. Here is what i was thinking, all i need is the
    "shown" month and year to complete.

    -----------------------------------------------
    Dim themonth as string = (need code to retreive "shown" month)
    Dim theyear as string = (need code to retreive "shown" year)
    Dim BeginRange as date
    Dim EndRange as date
    BeginRange = themonth & "/1/" & theyear
    Dim daysinmonth As Integer = BeginRange.DaysInMonth(theyear, themonth)
    EndRange = themonth & "/" & daysinmonth & "/" & theyear
    -----------------------------------------------

    any help would be greatly appreciated, and i'm sort of a .net newbie so
    if you could provide code examples it would be nice :p
    tfsmag, Jun 17, 2005
    #1
    1. Advertising

  2. tfsmag

    Kim Quigley Guest

    Let me know if this code works:
    Dim themonth As String = Me.Calendar1.VisibleDate.Month
    Dim theyear As String = Me.Calendar1.VisibleDate.Year

    "tfsmag" <> wrote in message
    news:...
    >i need to create a date range based on the current "shown" month on a
    > calendar control to query a database and populate a datagrid based on
    > that date range.
    >
    > how can i retrieve the "shown" month and year from the calendar control
    > to create this range. Here is what i was thinking, all i need is the
    > "shown" month and year to complete.
    >
    > -----------------------------------------------
    > Dim themonth as string = (need code to retreive "shown" month)
    > Dim theyear as string = (need code to retreive "shown" year)
    > Dim BeginRange as date
    > Dim EndRange as date
    > BeginRange = themonth & "/1/" & theyear
    > Dim daysinmonth As Integer = BeginRange.DaysInMonth(theyear, themonth)
    > EndRange = themonth & "/" & daysinmonth & "/" & theyear
    > -----------------------------------------------
    >
    > any help would be greatly appreciated, and i'm sort of a .net newbie so
    > if you could provide code examples it would be nice :p
    >
    Kim Quigley, Jun 17, 2005
    #2
    1. Advertising

  3. tfsmag

    tfsmag Guest

    no, that set themonth to "1" and theyear to "2001"
    tfsmag, Jun 17, 2005
    #3
  4. tfsmag

    tfsmag Guest

    i should also mention that i will need the variables to reflect the
    "shown" date, so that means when it moves forward a month, beginrange
    and endrange need to move forward a month.
    tfsmag, Jun 17, 2005
    #4
  5. tfsmag

    Kim Quigley Guest

    What was the actual visible date?

    "tfsmag" <> wrote in message
    news:...
    > no, that set themonth to "1" and theyear to "2001"
    >
    Kim Quigley, Jun 17, 2005
    #5
  6. tfsmag

    tfsmag Guest

    visible date was not set, if i set the visible date to date.now it
    doesn't change with the month. is there a way to make visibledate
    change when you click forward or backward a month?
    tfsmag, Jun 17, 2005
    #6
  7. tfsmag

    Kim Quigley Guest

    Now I'm confused about what you're asking. If you don't set VisibleDate
    anywhere, then it defaults to the current month until the user changes it.
    VisibleDate should always be the same as what you are actually seeing.

    Maybe you are putting your code in the wrong spot. I tried checking
    VisibleDate from the Page_Load, but it wasn't set. Try putting your code
    inside the VisibleMonthChanged method. Of course, someone will actually have
    to change the month for this event to fire. But if the month hasn't been
    changed or set, then you'll know what the values of BeginRange and EndRange
    should be (the current month)

    Private Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.MonthChangedEventArgs) Handles
    Calendar1.VisibleMonthChanged
    Dim themonth As String = Me.Calendar1.VisibleDate.Month
    Dim theyear As String = Me.Calendar1.VisibleDate.Year
    Dim BeginRange As Date
    Dim EndRange As Date
    BeginRange = themonth & "/1/" & theyear
    Dim daysinmonth As Integer = BeginRange.DaysInMonth(theyear, themonth)
    EndRange = themonth & "/" & daysinmonth & "/" & theyear
    End Sub

    "tfsmag" <> wrote in message
    news:...
    > visible date was not set, if i set the visible date to date.now it
    > doesn't change with the month. is there a way to make visibledate
    > change when you click forward or backward a month?
    >
    Kim Quigley, Jun 17, 2005
    #7
  8. tfsmag

    tfsmag Guest

    that last post helped me figure it out, thanks!
    tfsmag, Jun 17, 2005
    #8
  9. tfsmag

    Kim Quigley Guest

    Awesome!

    "tfsmag" <> wrote in message
    news:...
    > that last post helped me figure it out, thanks!
    >
    Kim Quigley, Jun 17, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tfsmag
    Replies:
    7
    Views:
    424
    Shimon Sim
    Jun 8, 2005
  2. =?Utf-8?B?SmFzb24gQ2hhbg==?=

    Get the month and year of Calendar that current displaying

    =?Utf-8?B?SmFzb24gQ2hhbg==?=, Nov 23, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    669
    Jason Chan
    Nov 23, 2005
  3. Replies:
    1
    Views:
    445
    Steve W. Jackson
    Dec 22, 2006
  4. Mufasa
    Replies:
    0
    Views:
    397
    Mufasa
    Sep 5, 2008
  5. Replies:
    7
    Views:
    216
    Idgarad
    Oct 6, 2006
Loading...

Share This Page