【发布时间】:2011-02-21 09:16:55
【问题描述】:
Dim List As New List(Of DateTime)
然后在我的按钮点击事件中:
If InputBookinglength.SelectedValue.ToString = "2" Then
Dim paramstring As New StringBuilder
If Session("SelectedDates") IsNot Nothing Then
Dim newList As List(Of DateTime) = DirectCast(Session("SelectedDates"), List(Of DateTime))
For Each dt As DateTime In newList
paramstring.Append(dt.ToShortDateString() & " - ")
Next
End If
command.Parameters.AddWithValue("@multibookingdates", paramstring.tostring)
然后我有:
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
If e.Day.IsSelected = True Then
List.Add(e.Day.[Date])
End If
Session("SelectedDates") = List
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
If Session("SelectedDates") IsNot Nothing Then
Dim newList As List(Of DateTime) = DirectCast(Session("SelectedDates"), List(Of DateTime))
For Each dt As DateTime In newList
Calendar1.SelectedDates.Add(dt)
Next
List.Clear()
End If
End Sub
Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
If Session("SelectedDates") IsNot Nothing Then
Dim newList As List(Of DateTime) = DirectCast(Session("SelectedDates"), List(Of DateTime))
For Each dt As DateTime In newList
Calendar1.SelectedDates.Add(dt)
Next
List.Clear()
End If
End Sub
End Class
在一个月内选择多天时,此代码可以正常工作。但是当您切换到显示不同的月份时,之前的月份选择会丢失。请您告诉我如何在可见月份更改时保留选择。
谢谢
【问题讨论】:
标签: c# asp.net vb.net datetime calendar