Calendar.SelectedDate Propiedad

Definición

Obtiene o establece la fecha seleccionada.

public:
 property DateTime SelectedDate { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Bindable(true)]
public DateTime SelectedDate { get; set; }
[System.ComponentModel.Bindable(true, System.ComponentModel.BindingDirection.TwoWay)]
public DateTime SelectedDate { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.SelectedDate : DateTime with get, set
[<System.ComponentModel.Bindable(true, System.ComponentModel.BindingDirection.TwoWay)>]
member this.SelectedDate : DateTime with get, set
Public Property SelectedDate As DateTime

Valor de propiedad

Un objeto DateTime que representa la fecha seleccionada. El valor predeterminado es DateTime.MinValue.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la SelectedDate propiedad para determinar la fecha seleccionada en el Calendar control.

<%@ 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>Calendar Example</title>
<script language="C#" runat="server">

      void Selection_Change(Object sender, EventArgs e) 
      {
         Label1.Text = "The selected date is " + Calendar1.SelectedDate.ToShortDateString();
      }

   </script>

</head>     
<body>

   <form id="form1" runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control.<br /><br />

      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="Day" 
           ShowGridLines="True"
           OnSelectionChanged="Selection_Change">
 
         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>
      
      </asp:Calendar>     

      <hr /><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>Calendar Example</title>
<script language="VB" runat="server">
        Sub Selection_Change(sender As Object, e As EventArgs)
            Label1.Text = "The selected date is " & Calendar1.SelectedDate.ToShortDateString()
        End Sub 'Selection_Change 
   </script>

</head>     
<body>

   <form id="form1" runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control.<br /><br />

      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="Day" 
           ShowGridLines="True"
           OnSelectionChanged="Selection_Change">
 
         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>
      
      </asp:Calendar>     

      <hr /><br />

      <asp:Label id="Label1" runat="server" />

   </form>
</body>
</html>

Comentarios

Utilice la SelectedDate propiedad para determinar la fecha seleccionada en el Calendar control.

La SelectedDate propiedad y la SelectedDates colección están estrechamente relacionadas. Cuando la SelectionMode propiedad se establece CalendarSelectionMode.Dayen , un modo que solo permite una selección SelectedDate de fecha única y SelectedDates[0] tiene el mismo valor y SelectedDates.Count es igual a 1. Cuando la SelectionMode propiedad se establece CalendarSelectionMode.DayWeek en o CalendarSelectionMode.DayWeekMonth, modos que permiten varias selecciones de SelectedDate fecha y SelectedDates[0] tienen el mismo valor.

La SelectedDate propiedad se establece mediante un System.DateTime objeto .

Cuando el usuario selecciona una fecha en el Calendar control, se genera el SelectionChanged evento . La SelectedDate propiedad se actualiza a la fecha seleccionada. La SelectedDates colección también se actualiza para que contenga solo esta fecha.

Nota

Tanto la SelectedDate propiedad como la SelectedDates colección se actualizan antes de que se genere el SelectionChanged evento. Puede invalidar la selección de fecha mediante el OnSelectionChanged controlador de eventos para establecer manualmente la SelectedDate propiedad . El SelectionChanged evento no se genera cuando esta propiedad se establece mediante programación.

Se aplica a

Consulte también