Calendar.TodaysDate Proprietà

Definizione

Ottiene o imposta il valore per la data odierna.

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

Valore della proprietà

DateTime

Oggetto DateTime che contiene il valore che l'oggetto Calendar considera data odierna. Se questa proprietà non è impostata in modo esplicito, verrà utilizzata la data del server.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come usare la proprietà per impostare a livello di codice il TodaysDate valore per la data odierna del Calendar controllo.

<%@ 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) 
      {
         Calendar1.TodaysDate = Calendar1.SelectedDate;
         Label1.Text = "Today's Date is now " + Calendar1.TodaysDate.ToShortDateString();
      }

   </script>

</head>     
<body>

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

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<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)
            Calendar1.TodaysDate = Calendar1.SelectedDate
            Label1.Text = "Today's Date is now " & Calendar1.TodaysDate.ToShortDateString()
        End Sub 'Selection_Change

   </script>

</head>     
<body>

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

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<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>

Commenti

Utilizzare la proprietà per determinare la TodaysDate data di oggi. È anche possibile usare questa proprietà per impostare a livello di codice il valore per la data odierna del Calendar controllo. Questa proprietà viene impostata usando un System.DateTime oggetto.

Nota

Questa data potrebbe essere regolata per ospitare gli utenti che si trovano in un fuso orario diverso.

L'aspetto della data specificata dalla TodaysDate proprietà può essere personalizzato usando la TodayDayStyle proprietà .

Nota

Se la VisibleDate proprietà non è impostata, la data specificata dalla TodaysDate proprietà determina quale mese viene visualizzato nel Calendar controllo.

Si applica a

Vedi anche