SelectedDatesCollection Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
public ref class SelectedDatesCollection sealed : System::Collections::ICollection
public sealed class SelectedDatesCollection : System.Collections.ICollection
type SelectedDatesCollection = class
interface ICollection
interface IEnumerable
Public NotInheritable Class SelectedDatesCollection
Implements ICollection
- Ereditarietà
-
SelectedDatesCollection
- Implementazioni
Esempio
Nell'esempio di codice seguente viene illustrato come usare la SelectedDatesCollection classe a livello di codice per selezionare le date nel Calendar controllo .
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
DisplayCalendar.VisibleDate = DisplayCalendar.TodaysDate;
}
void SelectButton_Click(Object sender, EventArgs e)
{
int current_day = DisplayCalendar.VisibleDate.Day;
int current_month = DisplayCalendar.VisibleDate.Month;
int current_year = DisplayCalendar.VisibleDate.Year;
DisplayCalendar.SelectedDates.Clear();
// Iterate through the current month and add all Wednesdays to the
// SelectedDates collection of the Calendar control.
for (int i = 1; i <= System.DateTime.DaysInMonth(current_year, current_month); i++)
{
DateTime currentDate = new DateTime(current_year, current_month, i);
if (currentDate.DayOfWeek == DayOfWeek.Wednesday)
{
DisplayCalendar.SelectedDates.Add(currentDate);
}
}
MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();
}
void DisplayCalendar_SelectionChanged(Object sender, EventArgs e)
{
MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:calendar id="DisplayCalendar" runat="server"
selectionmode="DayWeekMonth"
onselectionchanged="DisplayCalendar_SelectionChanged" />
<hr />
<asp:button id="SelectButton"
text="Select All Weds in Month"
onclick="SelectButton_Click"
runat="server"/>
<br/>
<asp:label id="MessageLabel"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
DisplayCalendar.VisibleDate = DisplayCalendar.TodaysDate
End Sub
Sub SelectButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim current_day As Integer = DisplayCalendar.VisibleDate.Day
Dim current_month As Integer = DisplayCalendar.VisibleDate.Month
Dim current_year As Integer = DisplayCalendar.VisibleDate.Year
DisplayCalendar.SelectedDates.Clear()
' Iterate through the current month and add all Wednesdays to the
' SelectedDates collection of the Calendar control.
Dim i As Integer
For i = 1 To System.DateTime.DaysInMonth(current_year, current_month)
Dim currentDate As New DateTime(current_year, current_month, i)
If currentDate.DayOfWeek = DayOfWeek.Wednesday Then
DisplayCalendar.SelectedDates.Add(currentDate)
End If
Next
MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString()
End Sub
Sub DisplayCalendar_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
MessageLabel.Text = "Selection Count = " & DisplayCalendar.SelectedDates.Count.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:calendar id="DisplayCalendar" runat="server"
selectionmode="DayWeekMonth"
onselectionchanged="DisplayCalendar_SelectionChanged" />
<hr />
<asp:button id="SelectButton"
text="Select All Weds in Month"
onclick="SelectButton_Click"
runat="server"/>
<br/>
<asp:label id="MessageLabel"
runat="server" />
</form>
</body>
</html>
Commenti
Utilizzare questa classe per gestire a livello di codice una raccolta di System.DateTime oggetti che rappresentano le date selezionate in un Calendar controllo . Questa classe viene comunemente usata per aggiungere o rimuovere date dalla raccolta.
Questa raccolta archivia solo le date intere. La parte temporale di ogni System.DateTime oggetto viene rimossa. Le date vengono archiviate in ordine crescente. Se sono presenti date duplicate, nella raccolta viene archiviata una sola data.
Costruttori
| Nome | Descrizione |
|---|---|
| SelectedDatesCollection(ArrayList) |
Inizializza una nuova istanza della SelectedDatesCollection classe con l'elenco di date specificato. |
Proprietà
| Nome | Descrizione |
|---|---|
| Count |
Ottiene il numero di DateTime oggetti nell'insieme SelectedDatesCollection . |
| IsReadOnly |
Ottiene un valore che indica se l'insieme SelectedDatesCollection è di sola lettura. |
| IsSynchronized |
Ottiene un valore che indica se l'accesso SelectedDatesCollection alla raccolta è sincronizzato (thread-safe). |
| Item[Int32] |
Ottiene un DateTime oggetto in corrispondenza dell'indice specificato nell'insieme SelectedDatesCollection . |
| SyncRoot |
Ottiene l'oggetto che può essere utilizzato per sincronizzare l'accesso all'insieme SelectedDatesCollection . |
Metodi
| Nome | Descrizione |
|---|---|
| Add(DateTime) |
Accoda l'oggetto specificato DateTime alla fine dell'insieme SelectedDatesCollection . |
| Clear() |
Rimuove tutti gli DateTime oggetti dall'insieme. |
| Contains(DateTime) |
Restituisce un valore che indica se l'insieme SelectedDatesCollection contiene l'oggetto specificato DateTime . |
| CopyTo(Array, Int32) |
Copia gli elementi dalla raccolta all'oggetto SelectedDatesCollection specificato Array, a partire dall'indice specificato. |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetEnumerator() |
Restituisce un IEnumeratoroggetto implementato da che contiene tutti gli DateTime oggetti all'interno dell'insieme SelectedDatesCollection . |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| Remove(DateTime) |
Rimuove l'oggetto specificato DateTime dall'insieme SelectedDatesCollection . |
| SelectRange(DateTime, DateTime) |
Aggiunge l'intervallo specificato di date all'insieme SelectedDatesCollection . |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Metodi di estensione
| Nome | Descrizione |
|---|---|
| AsParallel(IEnumerable) |
Abilita la parallelizzazione di una query. |
| AsQueryable(IEnumerable) |
Converte un IEnumerable in un IQueryable. |
| Cast<TResult>(IEnumerable) |
Esegue il cast degli elementi di un IEnumerable al tipo specificato. |
| OfType<TResult>(IEnumerable) |
Filtra gli elementi di un IEnumerable in base a un tipo specificato. |