.NET Framework Class Library
Calendar.SelectedDate Property

Gets or sets the selected date.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Syntax

Visual Basic (Declaration)
<BindableAttribute(True, BindingDirection.TwoWay)> _
Public Property SelectedDate As DateTime
Visual Basic (Usage)
Dim instance As Calendar
Dim value As DateTime

value = instance.SelectedDate

instance.SelectedDate = value
C#
[BindableAttribute(true, BindingDirection.TwoWay)] 
public DateTime SelectedDate { get; set; }
C++
[BindableAttribute(true, BindingDirection::TwoWay)] 
public:
property DateTime SelectedDate {
    DateTime get ();
    void set (DateTime value);
}
J#
/** @property */
public DateTime get_SelectedDate ()

/** @property */
public void set_SelectedDate (DateTime value)
JScript
public function get SelectedDate () : DateTime

public function set SelectedDate (value : DateTime)

Property Value

A System.DateTime that represents the selected date. The default value is DateTime.MinValue.
Remarks

Use the SelectedDate property to determine the selected date on the Calendar control.

The SelectedDate property and the SelectedDates collection are closely related. 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. 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.

The SelectedDate property is set using a System.DateTime object.

When the user selects a date on the Calendar control, the SelectionChanged event is raised. The SelectedDate property is updated to the selected date. The SelectedDates collection is also updated to contain just this date.

NoteNote

Both the SelectedDate property and the SelectedDates collection are updated before the SelectionChanged event is raised. You can override the date selection by using the OnSelectionChanged event handler to manually set the SelectedDate property. The SelectionChanged event does not get raised when this property is programmatically set.

TopicLocation
How to: Read Selected Dates in the Calendar Web Server ControlBuilding ASP .NET Web Applications
How to: Read Selected Dates in the Calendar Web Server ControlBuilding ASP .NET Web Applications
How to: Read Selected Dates in the Calendar Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Read Selected Dates in the Calendar Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Set Today's Date Programmatically in a Calendar Web Server ControlBuilding ASP .NET Web Applications
How to: Set Today's Date Programmatically in a Calendar Web Server ControlBuilding ASP .NET Web Applications
How to: Set Today's Date Programmatically in a Calendar Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Set Today's Date Programmatically in a Calendar Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Web Page in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Web Page in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Web Page in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Example

The following code example demonstrates how to use the SelectedDate property to determine the selected date on the Calendar control.

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <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 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>
C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

   <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 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>
JScript
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JScript" runat="server">

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

   </script>

</head>     
<body>

   <form 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>
Platforms

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Framework

Supported in: 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker