Deselect dates in Web Calendar c#
- by yomismo
Hello,
I'm trying to select and de-select dates on a C# Web Calendar control.
The problem I have is that I can select or deselect dates except when there is only a single date selected.
Clicking on it does not trigger the selection changed event, so Ineed to do something on the dayrender event but I'm not sure what or how.
Any ideas?
TIA
Code so far:
public static List<DateTime> list = new List<DateTime>();
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsSelected == true)
{
list.Add(e.Day.Date);
}
Session["SelectedDates"] = list;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime selection = Calendar1.SelectedDate;
if (Session["SelectedDates"] != null)
{
List<DateTime> newList = (List<DateTime>)Session["SelectedDates"];
foreach (DateTime dt in newList)
{
Calendar1.SelectedDates.Add(dt);
}
if (searchdate(selection, newList))
{
Calendar1.SelectedDates.Remove(selection);
}
list.Clear();
}
}
public bool searchdate(DateTime date, List<DateTime> dates)
{
var query = from o in dates
where o.Date == date
select o;
if (query.ToList().Count == 0)
{
return false;
}
else
{
return true;
}
}