Compartir a través de


SelectedDatesCollection.Item[Int32] Propiedad

Definición

Obtiene un objeto DateTime en el índice especificado de la colección 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

Valor de índice ordinal que especifica qué objeto DateTime se devuelve.

Valor de propiedad

Objeto DateTime que representa un elemento de SelectedDatesCollection.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el indexador para obtener un System.DateTime objeto de una SelectedDatesCollection colección. Tenga en cuenta que la SelectedDates propiedad del Calendar control es una instancia de la SelectedDatesCollection clase .

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

Comentarios

Utilice este indexador para obtener un objeto individual System.DateTime de la colección en el SelectedDatesCollection índice especificado mediante notación de matriz simple.

Se aplica a

Consulte también