SelectedDatesCollection.Count Property
Gets the number of System.DateTime objects in the SelectedDatesCollection.
[Visual Basic] Public Overridable ReadOnly Property Count As Integer Implements _ ICollection.Count [C#] public virtual int Count {get;} [C++] public: __property virtual int get_Count(); [JScript] public function get Count() : int;
Property Value
The number of System.DateTime objects in the SelectedDatesCollection.
Implements
Remarks
Use this property to determine the number of dates in the SelectedDatesCollection. The Count property is often used when iterating through the collection to determine the upper bound.
Example
[Visual Basic, C#] The following example demonstrates how use to the Count property to determine the number of dates in the 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 Button_Click(sender As Object, e As EventArgs) If Calendar1.SelectedDates.Count > 0 Then Label1.Text = "Selected date(s) are: " Dim i As Integer For i = 0 To Calendar1.SelectedDates.Count - 1 Label1.Text &= " " &+ Calendar1.SelectedDates(i).Day.ToString() Next i Else Label1.Text = "No dates selected!!" End If End Sub </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth"/> <hr> <asp:Button id="Button1" text="Display Selected Dates" OnClick="Button_Click" runat=server /> <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 Button_Click(Object sender, EventArgs e) { if (Calendar1.SelectedDates.Count > 0) { Label1.Text = "Selected date(s) are: "; for (int i = 0; i < Calendar1.SelectedDates.Count; i++) { Label1.Text += " " + Calendar1.SelectedDates[i].Day.ToString(); } } else Label1.Text = "No dates selected!!"; } </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth"/> <hr> <asp:Button id="Button1" text="Display Selected Dates" OnClick="Button_Click" runat=server /> <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