Calendar.SelectedDate Propriedade

Definição

Obtém ou define a data selecionada.Gets or sets the selected date.

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 da propriedade

DateTime

Um DateTime que representa a data selecionada.A DateTime that represents the selected date. O valor padrão é MinValue.The default value is MinValue.

Atributos

Exemplos

O exemplo de código a seguir demonstra como usar a SelectedDate propriedade para determinar a data selecionada no Calendar controle.The following code example demonstrates how to use the SelectedDate property to determine the selected date on the 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>

Comentários

Use a SelectedDate propriedade para determinar a data selecionada no Calendar controle.Use the SelectedDate property to determine the selected date on the Calendar control.

A SelectedDate propriedade e a SelectedDates coleção estão fortemente relacionadas.The SelectedDate property and the SelectedDates collection are closely related. Quando a SelectionMode propriedade é definida como CalendarSelectionMode.Day , um modo que permite apenas uma única seleção de data SelectedDate e que SelectedDates[0] tem o mesmo valor e SelectedDates.Count é igual a 1.When the SelectionMode property is set to CalendarSelectionMode.Day, a mode that allows only a single date selection, SelectedDate and SelectedDates[0] have the same value and SelectedDates.Count equals 1. Quando a SelectionMode propriedade é definida como CalendarSelectionMode.DayWeek or CalendarSelectionMode.DayWeekMonth , os modos que permitem várias seleções de data SelectedDate e SelectedDates[0] têm o mesmo valor.When the SelectionMode property is set to CalendarSelectionMode.DayWeek or CalendarSelectionMode.DayWeekMonth, modes that allows multiple date selections, SelectedDate and SelectedDates[0] have the same value.

A SelectedDate propriedade é definida usando um System.DateTime objeto.The SelectedDate property is set using a System.DateTime object.

Quando o usuário seleciona uma data no Calendar controle, o SelectionChanged evento é gerado.When the user selects a date on the Calendar control, the SelectionChanged event is raised. A SelectedDate propriedade é atualizada para a data selecionada.The SelectedDate property is updated to the selected date. A SelectedDates coleção também é atualizada para conter apenas essa data.The SelectedDates collection is also updated to contain just this date.

Observação

A SelectedDate propriedade e a SelectedDates coleção são atualizadas antes do SelectionChanged evento ser gerado.Both the SelectedDate property and the SelectedDates collection are updated before the SelectionChanged event is raised. Você pode substituir a seleção de data usando o OnSelectionChanged manipulador de eventos para definir manualmente a SelectedDate propriedade.You can override the date selection by using the OnSelectionChanged event handler to manually set the SelectedDate property. O SelectionChanged evento não é gerado quando essa propriedade é definida de forma programática.The SelectionChanged event does not get raised when this property is programmatically set.

Aplica-se a

Confira também