共用方式為


SelectedDatesCollection.Item[Int32] 屬性

定義

取得位於 DateTime 集合中指定索引的 SelectedDatesCollection 物件。

public:
 property DateTime default[int] { DateTime get(int index); };
public DateTime this[int index] { get; }
member this.Item(int) : DateTime
Default Public ReadOnly Property Item(index As Integer) As DateTime

參數

index
Int32

指定要傳回那個 DateTime 的循序索引值。

屬性值

DateTime,表示 SelectedDatesCollection 中的項目。

範例

下列程式碼範例示範如何使用索引子從 SelectedDatesCollection 集合取得 System.DateTime 物件。 請注意, SelectedDates 控制項的 Calendar 屬性是 類別 SelectedDatesCollection 的實例。

<%@ 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 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 id="form1" 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>
<%@ 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 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 id="form1" 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>

備註

使用此索引子,使用簡單的陣列標記法,在集合中 SelectedDatesCollection 取得集合中的個別 System.DateTime 物件。

適用於

另請參閱