views:

610

answers:

1

I have code to do multiple selections in a calendar control but I would like to change the color of the initially selected day to green and the end date to red. Visually this would indicate the start date and end date of a certain service to be provided. Should I be looking into RenderControl Method for my calander or more looking into setting some attribute of the days in the control?

The multiple select code is attributable to Steve Wellins

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        System.Web.UI.WebControls.Calendar TheCalendar = sender as System.Web.UI.WebControls.Calendar;

        // create new list of dates or get stored list of dates
        List SelectedDates;

        if (ViewState["SelectedDates"] == null)
            SelectedDates = new List();
        else
            SelectedDates = ViewState["SelectedDates"] as List;

        // if date is already in list, remove it, otherwise, add it
        if (SelectedDates.Contains(TheCalendar.SelectedDate) == false)
            SelectedDates.Add(Calendar1.SelectedDate);
        else
            SelectedDates.Remove(Calendar1.SelectedDate);

        // set the calendar to our list of dates
        TheCalendar.SelectedDates.Clear();
        foreach (DateTime Date in SelectedDates)
            TheCalendar.SelectedDates.Add(Date);

        // store list for next postback
        ViewState["SelectedDates"] = SelectedDates;
    }


This code may overwrite any date or formatting applied to the calendar but I am not above saving and restoring this formating to the calendar.


foreach (DateTime Date in SelectedDates)
                TheCalendar.SelectedDates.Add(Date);

I am glad to research leads if you point me down the right path or terms to search for.

A: 

From the MSDN site the Calendar..::.OnDayRender Method is invoked while each day is being rendered. I am a .NET noob... how to use it all?

ojblass