开发者

Persisting date selections when visible month changes

开发者 https://www.devze.com 2023-02-12 21:50 出处:网络
Dim List As New List(Of DateTime) Then in my button click event: If InputBookinglength.SelectedValue.ToString = \"2\" Then
Dim List As New List(Of DateTime)

Then in my button click event:

 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)

I then have:

  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

This code works fine when selecting multiple days in one month. But when you switch to display a different month, the previous months selections are lost. Please can you show me how to persist the selections when the visible month changes.

Thanks


In this case the quickest way to get the results I wanted was to put down the wheel and the chissel and use third party controls from obout (The calendar control).

Then capturing multiple dates is as simple as setting multiselect dates true:

 <obout:Calendar ID="MultiCalendar" runat="server" MultiSelectedDates="true" 
    Columns="1" CultureName="en-GB" TitleText="" ShowMonthSelector="true" 
    MonthSelectorType="DropDownList" >
    </obout:Calendar>

I can then get at the values like so:

 Dim dateString As New StringBuilder
            For Each item As String In MultiCalendar.SelectedDates
                dateString.Append(item)
                dateString.Append(" - ")
            Next
            command.Parameters.AddWithValue("@multibookingdates", dateString.ToString)

You can get the calendar control from http://www.obout.com

0

精彩评论

暂无评论...
验证码 换一张
取 消