SelectedDates Property
Returns a collection of selected dates from the ASP.NET SelectedDatesCollection class.
public System.Web.UI.WebControls.SelectedDatesCollection SelectedDates {
get
}
Remarks
Represents a collection of selected dates in a Calendar control.
Example
The following example demonstrates how to use of the SelectedDates property to select all of the Wednesdays in the current month.
Sub Button_Click(sender As Object, e As EventArgs)
Dim current_day As Integer = calendar1.VisibleDate.Day
Dim current_month As Integer = calendar1.VisibleDate.Month
Dim current_year As Integer = calendar1.VisibleDate.Year
calendar1.SelectedDates.Clear()
' Loop through current month and add all Wednesdays to the collection.
Dim i As Integer
For i = 1 To System.DateTime.DaysInMonth(current_year, current_month)
Dim targetDate As New DateTime(current_year, current_month, i)
If targetDate.DayOfWeek = DayOfWeek.Wednesday Then
calendar1.SelectedDates.Add(targetDate)
End If
Next i
Label1.Text = "Selection Count =" + calendar1.SelectedDates.Count.ToString()
End Sub
[C#]
void Button_Click(Object sender, EventArgs e)
{
int current_day = calendar1.VisibleDate.Day;
int current_month = calendar1.VisibleDate.Month;
int current_year = calendar1.VisibleDate.Year;
calendar1.SelectedDates.Clear();
// Loop through current month and add all Wednesdays to the collection.
for (int i = 1; i <= System.DateTime.DaysInMonth(current_year,
current_month); i++)
{
DateTime targetDate = new DateTime(current_year, current_month, i);
if (targetDate.DayOfWeek == DayOfWeek.Wednesday)
calendar1.SelectedDates.Add(targetDate);
}
Label1.Text = "Selection Count ="
+ calendar1.SelectedDates.Count;
}
See Also
Applies to: Calendar Class