SelectedDatesCollection.Item Property
Gets a System.DateTime at the specified index in the SelectedDatesCollection.
[C#] In C#, this property is the indexer for the SelectedDatesCollection class.
[Visual Basic] Public Default ReadOnly Property Item( _ ByVal index As Integer _ ) As DateTime [C#] public DateTime this[ int index ] {get;} [C++] public: __property DateTime get_Item( int index ); [JScript] returnValue = SelectedDatesCollectionObject.Item(index); -or- returnValue = SelectedDatesCollectionObject(index);
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.
Arguments [JScript]
- index
- An ordinal index value that specifies which System.DateTime to return.
Parameters [Visual Basic, C#, C++]
- index
- An ordinal index value that specifies which System.DateTime to return.
Property Value
A System.DateTime that represents an element in the SelectedDatesCollection.
Remarks
Use this indexer to get an individual System.DateTime in the SelectedDatesCollection at the specified index using simple array notation.
Example
[Visual Basic, C#] The following example demonstrates how to use the indexer to get a System.DateTime from a SelectedDatesCollection. Note that the SelectedDates property of the Calendar is an instance of the SelectedDatesCollection class.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub Selection_Change(sender As Object, e As EventArgs) Dim current_month As Integer = Calendar1.VisibleDate.Month Dim current_year As Integer = Calendar1.VisibleDate.Year Dim i As Integer For i = 0 To Calendar1.SelectedDates.Count - 1 If Calendar1.SelectedDates(i).DayOfWeek = DayOfWeek.Wednesday Then Label1.Text = "Wednesday falls on " & _ Calendar1.SelectedDates(i).Month & "/" & _ Calendar1.SelectedDates(i).Day & "/" & _ Calendar1.SelectedDates(i).Year End If Next i If Calendar1.SelectedDates.Count <> 7 Then Label1.Text = "" End If End Sub </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" OnSelectionChanged="Selection_Change" /> <hr> Select an entire week <br><br> <asp:Label id="Label1" runat=server /> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void Selection_Change(Object sender, EventArgs e) { int current_month = Calendar1.VisibleDate.Month; int current_year = Calendar1.VisibleDate.Year; for (int i = 0; i < Calendar1.SelectedDates.Count; i++) { if (Calendar1.SelectedDates[i].DayOfWeek == DayOfWeek.Wednesday) Label1.Text = "Wednesday falls on " + Calendar1.SelectedDates[i].Month + "/" + Calendar1.SelectedDates[i].Day + "/" + Calendar1.SelectedDates[i].Year; } if (Calendar1.SelectedDates.Count != 7) Label1.Text = ""; } </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" OnSelectionChanged="Selection_Change" /> <hr> Select an entire week <br><br> <asp:Label id="Label1" runat=server /> </form> </body> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
SelectedDatesCollection Class | SelectedDatesCollection Members | System.Web.UI.WebControls Namespace | SelectedDates | Calendar | System.DateTime