: 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 ...
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 ...
I like to write functions to make the job easier ...
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
Using the function to select todays date ...
Call SelectDate(cboMonths, cboYears, Date.Now)