If the Calendar Web control's SelectionMode is set to anything other than None, the user can select a day or a range of dates. You can detect and respond to the user's choice.
To respond to a date selection
[Visual Basic]
Public Sub control_OnSelectionChanged (s As Object, _
e As EventArgs)
Note The event is raised only if the date selection is changed by user action in the control. For instance, if the user clicks the same date twice, the second click does not raise an event. The event is also not raised if you set a date range programmatically.
Information about date selection is available in these properties:
To determine how many dates are selected
[Visual Basic]
Public Sub Calendar1_OnSelectionChanged (s As Object, _
e As EventArgs)
Text1.Text = "You selected " & Calendar1.SelectedDates.Count " _
date(s)."
End Sub
If you've determined that the user has selected multiple dates, you can get the range.
To get the date range of a multi-date selection
[Visual Basic]
Public Sub Calendar1_OnSelectionChanged ( s As Object, _
e As DayRenderEvent)
If Calendar1.SelectedDates.Count > 1 Then
Dim FirstDate as DateTime
Dim LastDate as DateTime
FirstDate = SelectedDates[0]
LastDate = SelectedDates[SelectedDates.Count - 1]
txtFirstDate.Text = FirstDate.toString
txtLastDate.Text = LastDate.toString
End If
End Sub
To get the time span of a multi-date selection
[Visual Basic]
Public Sub Calendar1_OnSelectedionChanged ( s As Object, _
e As DayRenderEvent)
Dim ts as TimeSpan
ts = Calendar1.SelectedDates[SelectedDates.Count - 1] - _
Calendar1.SelectedDates[0]
Text1.Text = "You selected " & ts.Days+1 & " days."
End Sub
See Also