Partager via


SelectedDatesCollection.Item[Int32] Propriété

Définition

Obtient un objet DateTime situé à l'index spécifié dans la collection 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

Paramètres

index
Int32

Valeur d'index ordinale spécifiant l'objet DateTime à retourner.

Valeur de propriété

Objet DateTime représentant un élément du SelectedDatesCollection.

Exemples

L’exemple de code suivant montre comment utiliser l’indexeur pour obtenir un System.DateTime objet à partir d’une SelectedDatesCollection collection. Notez que la SelectedDates propriété du Calendar contrôle est une instance de la SelectedDatesCollection classe .

<%@ 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>

Remarques

Utilisez cet indexeur pour obtenir un objet individuel System.DateTime dans la SelectedDatesCollection collection à l’index spécifié à l’aide de la notation de tableau simple.

S’applique à

Voir aussi