ASP.NET Calendar - Knowledge Base

« Back to Knowledge Base list

Get/set multiple selected dates

Q:

How do I get the selected days in the calendar (with MultiSelectedDates option set)?
A second question – how do I populate multiple selected days onto the calendar?

A:

Here are the code samples.

Get selected dates:

lText.Text="The selected dates are:";
if (Calendar1.SelectedDates.Count > 0)  lText.Text += "<br />";
for (int index=0;index<Calendar1.SelectedDates.Count;index++)
{
    lText.Text += "<br />" + ((DateTime)Calendar1.SelectedDates[index]).ToString("d");
}


Set initially selected dates:

Calendar1.MultiSelectedDates = true;
Calendar1.SelectedDates = new OboutInc.Calendar2.Calendar.SelectedDatesList()
                 { new DateTime(2012, 7, 10), new DateTime(2012, 7, 11), new DateTime(2012, 7, 12) };