次の方法で共有


SelectedDatesCollection.Count プロパティ

SelectedDatesCollection コレクション内の System.DateTime オブジェクトの数を取得します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public ReadOnly Property Count As Integer
'使用
Dim instance As SelectedDatesCollection
Dim value As Integer

value = instance.Count
public int Count { get; }
public:
virtual property int Count {
    int get () sealed;
}
/** @property */
public final int get_Count ()
public final function get Count () : int
適用できません。

プロパティ値

SelectedDatesCollection 内の System.DateTime オブジェクトの数。

解説

このプロパティを使用して、SelectedDatesCollection コレクション内の日付の数を確認します。通常、Count プロパティは、コレクションを反復処理して上限を確認する場合に使用されます。

使用例

Count プロパティを使用して、SelectedDatesCollection コレクション内の日付の数を確認する方法を次のコード例に示します。Calendar コントロールの SelectedDates プロパティは、SelectedDatesCollection クラスのインスタンスです。

<%@ 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>ASP.NET Example</title>
<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 id="form1" 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>
 
<%@ 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>ASP.NET Example</title>
<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 id="form1" 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>
 

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

SelectedDatesCollection クラス
SelectedDatesCollection メンバ
System.Web.UI.WebControls 名前空間
Calendar.SelectedDates プロパティ
Calendar
System.DateTime