Language

Calendar.SelectedDate Property

Definition

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; }
[]
member this.SelectedDate : DateTime with get, set
[]
member this.SelectedDate : DateTime with get, set
Public Property SelectedDate As DateTime

Property Value

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

Attributes

Examples

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



    Calendar Example


     


   

Calendar Example

Select a date on the Calendar control.



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




    Calendar Example


     


   

Calendar Example

Select a date on the Calendar control.



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.

Note

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.

Applies to

See also