Calendar.TodaysDate Właściwość

Definicja

Pobiera lub ustawia wartość dla dzisiejszej daty.

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

Wartość właściwości

Element DateTime zawierający wartość, którą Calendar uważa się za bieżącą datę. Jeśli ta właściwość nie jest jawnie ustawiona, ta data będzie datą na serwerze.

Atrybuty

Przykłady

Poniższy przykład kodu pokazuje, jak za pomocą TodaysDate właściwości programowo ustawić wartość bieżącej daty w kontrolce Calendar .

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

Uwagi

Użyj właściwości , TodaysDate aby określić bieżącą datę. Można również użyć tej właściwości, aby programowo ustawić wartość bieżącej daty w kontrolce Calendar . Ta właściwość jest ustawiana przy użyciu System.DateTime obiektu.

Uwaga

Ta data może być konieczna, aby uwzględnić użytkowników, którzy znajdują się w innej strefie czasowej.

Wygląd daty określonej przez TodaysDate właściwość można dostosować przy użyciu TodayDayStyle właściwości .

Uwaga

VisibleDate Jeśli właściwość nie jest ustawiona, data określona przez TodaysDate właściwość określa, który miesiąc jest wyświetlany w kontrolceCalendar.

Dotyczy

Zobacz też