.NET Framework Class Library SelectedDatesCollection Class Encapsulates a collection of System..::.DateTime objects that represent the selected dates in a Calendar control. This class cannot be inherited.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public NotInheritable Class SelectedDatesCollection _
Implements ICollection, IEnumerable
public sealed class SelectedDatesCollection : ICollection,
IEnumerable
public ref class SelectedDatesCollection sealed : ICollection,
IEnumerable
[<Sealed>]
type SelectedDatesCollection =
class
interface ICollection
interface IEnumerable
end
The SelectedDatesCollection type exposes the following members.

Constructors
|
| Name | Description |
|---|
.gif) | SelectedDatesCollection | Initializes a new instance of the SelectedDatesCollection class with the specified date list. | Top

Methods

Extension Methods

Remarks
Use this class to programmatically manage a collection of System..::.DateTime objects that represent the selected dates in a Calendar control. This class is commonly used to add or remove dates from the collection. This collection stores only whole dates. The time portion of each System..::.DateTime is removed. The dates are stored in ascending order. If there are duplicate dates, only one date is stored in the collection.

Examples
The following code example demonstrates how to programmatically use the SelectedDatesCollection class to select dates in the Calendar control.
<%@ 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 >
<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="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 >
<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>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework SelectedDatesCollection, classe Encapsule une collection d'objets System..::.DateTime représentant les dates sélectionnées dans un contrôle Calendar. Cette classe ne peut pas être héritée.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public NotInheritable Class SelectedDatesCollection _
Implements ICollection, IEnumerable
public sealed class SelectedDatesCollection : ICollection,
IEnumerable
public ref class SelectedDatesCollection sealed : ICollection,
IEnumerable
[<Sealed>]
type SelectedDatesCollection =
class
interface ICollection
interface IEnumerable
end
Le type SelectedDatesCollection expose les membres suivants.

Constructeurs
|
| Nom | Description |
|---|
.gif) | SelectedDatesCollection | Initialise une nouvelle instance de la classe SelectedDatesCollection avec la liste de dates spécifiée. | Début

Méthodes

Méthodes d'extension

Notes
Utilisez cette classe pour gérer par programme une collection d'objets System..::.DateTime représentant les dates sélectionnées dans un contrôle Calendar. Cette classe est généralement utilisée pour ajouter des dates dans la collection ou en supprimer. Cette collection ne stocke que des dates complètes. La partie horaire de chaque System..::.DateTime est supprimée. Les dates sont stockées en ordre croissant. S'il y a des dates en double, une seule est stockée dans la collection.

Exemples
L'exemple de code suivant illustre la sélection de dates par programme dans le contrôle Calendar à l'aide de la classe SelectedDatesCollection.
<%@ 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 >
<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="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 >
<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>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0, 1.1, 1.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
|