Proprietà SelectedDates

Restituisce un insieme di date selezionate dalla classe SelectedDatesCollection di ASP .NET.

public System.Web.UI.WebControls.SelectedDatesCollection SelectedDates {
   get
}

Osservazioni

Rappresenta un insieme di date selezionate in controllo Calendar.

Esempio

Nell'esempio che segue viene illustrato come utilizzare la proprietà SelectedDates per selezionare tutti i mercoledì del mese corrente.

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;
}   

Vedere anche

Si applica a: classe Calendar