SelectedDatesCollection Klasa
Definicja
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
- Dziedziczenie
-
SelectedDatesCollection
- Implementuje
Przykłady
Poniższy przykład kodu demonstruje, jak programowo użyć SelectedDatesCollection klasy do wybrania dat w Calendar kontrolce.The following code example demonstrates how to programmatically use the SelectedDatesCollection class to select dates in the Calendar control.
<%@ 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>
Uwagi
Użyj tej klasy, aby programowo zarządzać kolekcją System.DateTime obiektów, które reprezentują wybrane daty w Calendar kontrolce.Use this class to programmatically manage a collection of System.DateTime objects that represent the selected dates in a Calendar control. Ta klasa jest często używana do dodawania lub usuwania dat z kolekcji.This class is commonly used to add or remove dates from the collection.
W tej kolekcji są przechowywane tylko całe daty.This collection stores only whole dates. Część czasu każdej z nich System.DateTime zostanie usunięta.The time portion of each System.DateTime is removed. Daty są przechowywane w kolejności rosnącej.The dates are stored in ascending order. Jeśli istnieją zduplikowane daty, w kolekcji jest przechowywana tylko jedna Data.If there are duplicate dates, only one date is stored in the collection.
Konstruktory
SelectedDatesCollection(ArrayList) |
Inicjuje nowe wystąpienie SelectedDatesCollection klasy z określoną listą dat.Initializes a new instance of the SelectedDatesCollection class with the specified date list. |
Właściwości
Count |
Pobiera liczbę DateTime obiektów w SelectedDatesCollection kolekcji.Gets the number of DateTime objects in the SelectedDatesCollection collection. |
IsReadOnly |
Pobiera wartość wskazującą, czy SelectedDatesCollection kolekcja jest tylko do odczytu.Gets a value indicating whether the SelectedDatesCollection collection is read-only. |
IsSynchronized |
Pobiera wartość wskazującą, czy dostęp do SelectedDatesCollection kolekcji jest synchronizowany (bezpieczny wątkowo).Gets a value indicating whether access to the SelectedDatesCollection collection is synchronized (thread safe). |
Item[Int32] |
Pobiera DateTime obiekt o określonym indeksie w SelectedDatesCollection kolekcji.Gets a DateTime object at the specified index in the SelectedDatesCollection collection. |
SyncRoot |
Pobiera obiekt, którego można użyć do synchronizowania dostępu do SelectedDatesCollection kolekcji.Gets the object that can be used to synchronize access to the SelectedDatesCollection collection. |
Metody
Add(DateTime) |
Dołącza określony DateTime obiekt do końca SelectedDatesCollection kolekcji.Appends the specified DateTime object to the end of the SelectedDatesCollection collection. |
Clear() |
Usuwa wszystkie DateTime obiekty z kolekcji.Removes all DateTime objects from the collection. |
Contains(DateTime) |
Zwraca wartość wskazującą czy SelectedDatesCollection Kolekcja zawiera określony DateTime obiekt.Returns a value indicating whether the SelectedDatesCollection collection contains the specified DateTime object. |
CopyTo(Array, Int32) |
Kopiuje elementy z SelectedDatesCollection kolekcji do określonego Array , rozpoczynając od określonego indeksu.Copies the items from the SelectedDatesCollection collection to the specified Array, starting with the specified index. |
Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.Determines whether the specified object is equal to the current object. (Odziedziczone po Object) |
GetEnumerator() |
Zwraca IEnumerator obiekt zaimplementowany, który zawiera wszystkie DateTime obiekty w SelectedDatesCollection kolekcji.Returns an IEnumerator-implemented object that contains all DateTime objects within the SelectedDatesCollection collection. |
GetHashCode() |
Służy jako domyślna funkcja skrótu.Serves as the default hash function. (Odziedziczone po Object) |
GetType() |
Pobiera Type bieżące wystąpienie.Gets the Type of the current instance. (Odziedziczone po Object) |
MemberwiseClone() |
Tworzy skróconą kopię bieżącego elementu Object .Creates a shallow copy of the current Object. (Odziedziczone po Object) |
Remove(DateTime) |
Usuwa określony DateTime obiekt z SelectedDatesCollection kolekcji.Removes the specified DateTime object from the SelectedDatesCollection collection. |
SelectRange(DateTime, DateTime) |
Dodaje określony zakres dat do SelectedDatesCollection kolekcji.Adds the specified range of dates to the SelectedDatesCollection collection. |
ToString() |
Zwraca ciąg reprezentujący bieżący obiekt.Returns a string that represents the current object. (Odziedziczone po Object) |
Metody rozszerzania
Cast<TResult>(IEnumerable) |
Rzutuje elementy elementu IEnumerable do określonego typu.Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Filtruje elementy IEnumerable w oparciu o określony typ.Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Włącza przetwarzanie równoległe zapytania.Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Konwertuje IEnumerable do IQueryable .Converts an IEnumerable to an IQueryable. |