SelectedDatesCollection クラス
アセンブリ: System.Web (system.web.dll 内)


このクラスを使用して、Calendar コントロールで選択されている日付を表す System.DateTime オブジェクトのコレクションをプログラムによって管理します。通常、このクラスはコレクションから日付を追加または削除するために使用します。
このコレクションは、日付だけを格納します。各 System.DateTime の時間部分は削除されます。日付は昇順で格納されます。重複する日付がある場合、コレクションに格納されるのは 1 日だけです。

プログラムによって SelectedDatesCollection クラスを使用し、Calendar コントロールで日付を選択する方法を次のコード例に示します。
<%@ Page Language="VB"%> <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> <body> <form 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#"%> <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> <body> <form 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>

System.Web.UI.WebControls.SelectedDatesCollection


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SelectedDatesCollection クラスのページへのリンク