Inherits System.Web.UI.Page
Dim Year, Month As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tnow As DateTime
tnow = DateTime.Now
Dim AlYear As New ArrayList
Dim i As Integer
For i = 2000 To 2010
AlYear.Add(i)
Next
Dim AlMonth As New ArrayList
For i = 1 To 12
AlMonth.Add(i)
Next
If IsPostBack = False Then
DropDownList1.DataSource = AlYear
DropDownList1.DataBind()
DropDownList1.SelectedValue = tnow.Year.ToString()
DropDownList2.DataSource = AlMonth
DropDownList2.DataBind()
DropDownList2.SelectedValue = tnow.Month.ToString()
Year = Int32.Parse(DropDownList1.SelectedValue)
Month = Int32.Parse(DropDownList2.SelectedValue)
BindDays(Year, Month)
DropDownList3.SelectedValue = tnow.Day.ToString()
End If
Label1.Text = "You select date:" + DropDownList1.SelectedValue + "year" + DropDownList2.SelectedValue + "month" + DropDownList3.SelectedValue
End Sub
'judge leap year
Private Function CheckLeap(ByVal year As Integer) As Boolean
If (year Mod 4 = 0) And (year Mod 100 <> 0) Or (year Mod 400 = 0) Then
Return True
Else
Return False
End If
End Function
'binding every month day
Private Function BindDays(ByVal year As Integer, ByVal month As Integer)
Dim i As Integer
Dim AlDay As New ArrayList
Select Case month
Case 1, 3, 5, 7, 8, 10, 12
For i = 1 To 31
AlDay.Add(i)
Next
Case 2
If CheckLeap(year) Then
For i = 1 To 29
AlDay.Add(i)
Next
Else
For i = 1 To 28
AlDay.Add(i)
Next
End If
Case 4, 6, 9, 11
For i = 1 To 30
AlDay.Add(i)
Next
End Select
DropDownList3.DataSource = AlDay
DropDownList3.DataBind()
End Function
'select year
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Year = Int32.Parse(DropDownList1.SelectedValue)
Month = Int32.Parse(DropDownList2.SelectedValue)
BindDays(Year, Month)
End Sub
'select month
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Year = Int32.Parse(DropDownList1.SelectedValue)
Month = Int32.Parse(DropDownList2.SelectedValue)
BindDays(Year, Month)
End Sub
End Class