Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
how can i set selection of multiple weeks in webmonthcalendar on page load
posted

i wanted to use this calendar to show a schedule of days that are reserved on a calendar.  they will have multiple weeks from different months and just need to highlight the days to show they are already reserved.  is there a way to do this on the page load event on my page or another control that i should use to accomplish what i need?

Parents
  • 24497
    posted

    Hi Mike,

    The WebMonthCalendar has property CustomDays. That allows to add special days to calendar which can be rendered with special styles. Below is example:

    aspx:

    <head runat="server">
        <style type="text/css">
        .customCss
        {
           font-weight:bold;
           background-color:#E0E0E0;
        }
        </style>
    </head>
    ...
    <ig:WebMonthCalendar ID="WebMonthCalendar1" runat="server"></ig:WebMonthCalendar>

    aspx.cs:

    protected void Page_Load (System.Object sender, System.EventArgs e)
    {
       if(!this.IsPostBack)
        this.AddCustomDays();
    }
    private void AddCustomDays()
    {
       this.WebMonthCalendar1.CustomDays.Clear();
       DateTime[] weeks = new DateTime[]{new DateTime(2010, 6, 13), new DateTime(2010, 6, 27), new DateTime(2010, 7, 4), new DateTime(2010, 8, 1), new DateTime(2010, 8, 15)};
       for(int i = 0; i < weeks.Length; i++)
        this.AddCustomWeek(weeks[i]);
    }
    private void AddCustomWeek(DateTime date)
    {
       for(int i = 0; i < 7; i++)
       {
        CalendarCustomDay day = new CalendarCustomDay(date);
        day.CssClass = "customCss";
        this.WebMonthCalendar1.CustomDays.Add(day);
        date = date.AddDays(1);
       }
    }

Reply Children