Deselect dates in Web Calendar c#

Posted by yomismo on Stack Overflow See other posts from Stack Overflow or by yomismo
Published on 2010-04-13T07:29:23Z Indexed on 2010/04/13 7:32 UTC
Read the original article Hit count: 902

Filed under:
|
|
|
|

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;
        }

    }

© Stack Overflow or respective owner

Related posts about web

Related posts about calendar