Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with calendar

marcoskn1marcoskn1 Posts: 61Member
i'm trying to put some dropdownlists , one to select year and another to select months

but i'd like these dropdowns to be with the current Month and Year of the calendar...

how can I do this ?


thanks!

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    : i'm trying to put some dropdownlists , one to select year and another to select months
    :
    : but i'd like these dropdowns to be with the current Month and Year of the calendar...
    :
    : how can I do this ?
    :
    :
    : thanks!
    :
    :

    The code could look something like this.

    Here is a sample of loading the dropdowns ...

    [code]
    cboMonths.Items.Add(New LisItem("January", "1"))
    cboMonths.Items.Add(New LisItem("February", "2"))
    cboMonths.Items.Add(New LisItem("March", "3"))
    ' etc ...

    ' I USUALLY use a loop to create this ...
    cboYears.Items.Add(New ListItem("2003"))
    cboYears.Items.Add(New ListItem("2002"))
    cboYears.Items.Add(New ListItem("2001"))
    ' etc ...
    [/code]

    I like to write functions to make the job easier ...

    [Code]

    Public Sub SelectDate(ByRef Month As DropDownList, ByRef Year As DropDownList, ByVal someDate As Date)

    Dim li As ListItem
    li = Month.Items.FindByValue(someDate.Month.ToString)
    If Not li Is Nothing Then li.Selected = True

    li = Year.Items.FindByValue(someDate.Year.ToString)
    If Not li Is Nothing Then li.Selected = True

    End Sub

    [/code]

    Using the function to select todays date ...

    [code]
    Call SelectDate(cboMonths, cboYears, Date.Now)
    [/code]

Sign In or Register to comment.