Assembly: System.Web (in System.Web.dll)
<BrowsableAttribute(False)> Public ReadOnly Property SelectedDates As SelectedDatesCollection
Use the Calendar control.collection to determine the currently selected dates on the
The SelectedDate property and the collection are closely related. When the SelectionMode property is set to CalendarSelectionMode.Day, a mode that allows only a single date selection, SelectedDate and SelectedDates have the same value and SelectedDates.Count equals 1. When the SelectionMode property is set to CalendarSelectionMode.DayWeek or CalendarSelectionMode.DayWeekMonth, modes that allows multiple date selections, SelectedDate and SelectedDates have the same value.
The System.DateTime objects.property stores a collection of
When the user selects a week or month on the Calendar control, the SelectionChanged event is raised. The selected dates are added to the collection, replacing the previous contents. The range of dates are sorted in ascending order by date. The SelectedDate property is also updated to contain the first date in the collection.
Both the SelectedDate property and the collection are updated before the SelectionChanged event is raised. You can override the date selection by using the OnSelectionChanged event handler to manually set the collection. The SelectionChanged event is not raised when this collection is programmatically set.
The following code example demonstrates how to use the Calendar control.collection to determine the selected dates on the
<%@ Page Language="VB" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Calendar Example</title> <script language="VB" runat="server"> Sub Selection_Change(sender As Object, e As EventArgs) Label1.Text = "The selected date(s):" & ChrW(60) & "br" & ChrW(62) Dim i As Integer For i = 0 To Calendar1.SelectedDates.Count - 1 Label1.Text &= Calendar1.SelectedDates(i).ToShortDateString() & ChrW(60) & "br" & ChrW(62) Next i End Sub 'Selection_Change </script> </head> <body> <form id="form1" runat="server"> <h3>Calendar Example</h3> Select date(s) on the Calendar control.<br /><br /> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" ShowGridLines="True" OnSelectionChanged="Selection_Change"> <SelectedDayStyle BackColor="Yellow" ForeColor="Red"> </SelectedDayStyle> </asp:Calendar> <hr /><br /> <asp:Label id="Label1" runat="server" /> </form> </body> </html>
Available since 1.1