You can set date selections in your own code, either a single date or a range of dates. In contrast to user selection in the control on a page, you can select multiple non-sequential dates in code.
Note Setting a date programmatically does not raise the SelectionChanged event.
To select a single date
To select a range of dates
The following example sets the selection to every Wednesday in the month of February, 2000.
[Visual Basic]
Public Sub Calendar1_OnSelectedionChanged (s As Object, _
Calendar1.SelectedDates.Clear
Calendar1.SelectedDates.Add new System.DateTime(2000, 2, 2)
Calendar1.SelectedDates.Add new System.DateTime(2000, 2, 9)
Calendar1.SelectedDates.Add new System.DateTime(2000, 2, 16)
Calendar1.SelectedDates.Add new System.DateTime(2000, 2, 23)
End Sub
The following example selects a sequence of seven dates.
Dim dt As New DateTime dt = "01/01/2000" Calendar1.SelectedDates.Add(dt) For i = 1 to 6 Calendar1.SelectedDates.Add(dt.AddDays(i)) Next i
To clear a date selection
Calendar1.SelectedDates.Clear
You can also set the SelectedDay property to DateTime.Empty to clear the selection of a single date.
[Visual Basic]
Calendar1.SelectedDay = new System.DateTime.Empty
See Also