SelectedDatesCollection.Clear メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コレクションからすべての DateTime オブジェクトを削除します。
public:
void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()
例
次のコード例では、 メソッドを使用ClearしてコレクションからSelectedDatesCollectionすべてのSystem.DateTimeオブジェクトを削除し、それらを新しいSystem.DateTimeオブジェクトに置き換える方法を示します。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SelectedDatesCollection Add Example </title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Initialize the VisibleDate property with today's date when
// the page is first loaded.
if(!IsPostBack)
{
Calendar1.VisibleDate = Calendar1.TodaysDate;
}
}
void Button_Click(Object sender, EventArgs e)
{
// This method demonstrates how to select noncontiguous dates
// in the calendar.
// Get the month and year of the date contained in the
// VisibleDate property.
int CurrentMonth = Calendar1.VisibleDate.Month;
int CurrentYear = Calendar1.VisibleDate.Year;
// Clear all selected dates.
Calendar1.SelectedDates.Clear();
// Iterate through the current month and add all Wednesdays
// to the collection.
for (int i = 1;
i <= System.DateTime.DaysInMonth(CurrentYear, CurrentMonth);
i++)
{
DateTime CurrentDate = new DateTime(CurrentYear, CurrentMonth, i);
if (CurrentDate.DayOfWeek == DayOfWeek.Wednesday)
{
Calendar1.SelectedDates.Add(CurrentDate);
}
}
// Display the number of items selected.
Message.Text = "Selection Count = " +
Calendar1.SelectedDates.Count.ToString();
}
void Selection_Change(Object sender, EventArgs e)
{
// Display the number of items selected.
Message.Text = "Selection Count = " +
Calendar1.SelectedDates.Count.ToString();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>SelectedDatesCollection Add Example </h3>
Click the button to select all Wednesdays in the month.
<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
OnSelectionChanged="Selection_Change" />
<hr />
<asp:Button id="SubmitButton"
Text="Select All Weds in Month"
OnClick="Button_Click"
runat="server" />
<br />
<asp:Label id="Message"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SelectedDatesCollection Add Example </title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Initialize the VisibleDate property with today's date when
' the page is first loaded.
If Not IsPostBack Then
Calendar1.VisibleDate = Calendar1.TodaysDate
End If
End Sub
Sub Button_Click(sender As Object, e As EventArgs)
' This method demonstrates how to select noncontiguous dates
' in the calendar.
' Get the month, day, and year of the date contained in the
' VisibleDate property.
Dim CurrentMonth As Integer = Calendar1.VisibleDate.Month
Dim CurrentYear As Integer = Calendar1.VisibleDate.Year
' Clear all selected dates.
Calendar1.SelectedDates.Clear()
' Iterate through the current month and add all Wednesdays
' to the collection.
Dim i As Integer
For i = 1 To System.DateTime.DaysInMonth(CurrentYear, CurrentMonth)
Dim CurrentDate As DateTime = _
New DateTime(CurrentYear, CurrentMonth, i)
If CurrentDate.DayOfWeek = DayOfWeek.Wednesday Then
Calendar1.SelectedDates.Add(CurrentDate)
End If
Next i
' Display the number of items selected.
Message.Text = "Selection Count = " & _
Calendar1.SelectedDates.Count.ToString()
End Sub
Sub Selection_Change(sender As Object, e As EventArgs)
' Display the number of items selected.
Message.Text = "Selection Count = " & _
Calendar1.SelectedDates.Count.ToString()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>SelectedDatesCollection Add Example </h3>
Click the button to select all Wednesdays in the month.
<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
OnSelectionChanged="Selection_Change" />
<hr />
<asp:Button id="SubmitButton"
Text="Select All Weds in Month"
OnClick="Button_Click"
runat="server" />
<br />
<asp:Label id="Message"
runat="server" />
</form>
</body>
</html>
注釈
コレクションからすべての System.DateTime オブジェクトを削除し、 プロパティを SelectedDatesCollection 0 に設定するには、このメソッドを Count 使用します。
適用対象
こちらもご覧ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET