Topic: Calendar control
Share/Save/Bookmark
Calendar control
 
To get or set dates selected on the Calendar control, use the "SelectionChanged" event procedure and the "SelectedDate" or
"SelectedDates" properties. "SelectionChanged" is a postback event, so the following code displays the selected date or
dates as soon as the selection changes:
 
The "SelectionMode" property allows you to set up the different types of selections that can be performed on the calendar.
For multiple date selections, you'll need to change this property.
 
private void Page_Load(object sender, System.EventArgs e)
{
   // Display the current date
   lblDate.Text = "Current date: " + calSource.TodaysDate;
}
 
private void calSource_SelectionChanged(object sender, System.EventArgs e)
{
   // Display the current date
   lblDate.Text = "Current date: " + calSource.TodaysDate;
   if (calSource.SelectedDates.Count == 1)
      // If one date is selected, display it
      lblDate.Text = "Selected date: " + calSource.SelectedDate;
   else
      // If multiple dates are selected, display them.
      lblDate.Text = "Selected dates: " + calSource.SelectedDates[0] + " to " + calSource.SelectedDates[calSource.SelectedDates.Count - 1];