在vb.net的DateTimePicker中选择多个日期?

时间:2012-01-24 09:58:30

标签: vb.net datetimepicker

无论如何我可以在Vb.net的日期时间选择器中选择多个日期吗?

1 个答案:

答案 0 :(得分:2)

Private listDates As List(Of DateTime)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'Suppose that you have the following list of dates below
    listDates = New List(Of DateTime)()
    listDates.Add(DateTime.Now)
    listDates.Add("12/22/2012")
    listDates.Add(DateTime.Now.AddDays(-10))
End Sub
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles Calendar1.DayRender
    'Set Default properties
    e.Day.IsSelectable = False
    e.Cell.BackColor = System.Drawing.Color.Gray
    'Now loop through the list of dates and make it
    'Selectable
    For Each d As DateTime In listDates
        Calendar1.SelectedDates.Add(d)
        If e.Day.IsSelected Then
            e.Cell.BackColor = System.Drawing.Color.Green
            e.Day.IsSelectable = True
        End If
    Next
End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
    'Print the selected date
    Response.Write("You have selected: " & Calendar1.SelectedDate.ToShortDateString())
End Sub

我找到了,然后试试。这行得通, 来自here

的原始来源