Partilhar via


SelectedDatesCollection.Item[Int32] Propriedade

Definição

Obtém um objeto DateTime no índice especificado na coleção 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

Parâmetros

index
Int32

Um valor de índice ordinal que especifica qual DateTime retornar.

Valor da propriedade

DateTime

Um DateTime que representa um elemento no SelectedDatesCollection.

Exemplos

O exemplo de código a seguir demonstra como usar o indexador para obter um System.DateTime objeto de uma SelectedDatesCollection coleção. Observe que a SelectedDates propriedade do Calendar controle é uma instância da 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>

Comentários

Use esse indexador para obter um objeto individual System.DateTime na SelectedDatesCollection coleção no índice especificado usando notação de matriz simples.

Aplica-se a

Confira também