Display required month on RadCalender

2 posts, 0 answers
  1. Anwar
    Anwar avatar
    31 posts
    Member since:
    Aug 2011

    Posted 16 Feb 2012 Link to this post

    Hai friends,

    We are using RadCalender in our application.
    By default RadCalender displaying current month.
    Our requirment is differ to this.

    in our code we are having a variable selectDate(this variable contains date).
    this selectDate may be less than current date or may be greater than the current date.

    Now depending on the date ,we have to display respective month calender.
     if selectDate="24/2/2012"  ,then RadCalender has to display feb month
     if selectDate="24/3/2012"  ,then RadCalender has to display march month

    Same requirement for RadScheduler also
     if selectDate="24/2/2012"  ,then RadScheduler has to display feb month
     if selectDate="24/3/2012"  ,then RadScheduler has to display march month

    how can i do this

    Thanks in advance

  2. Richard
    Richard avatar
    479 posts
    Member since:
    Nov 2011

    Posted 20 Feb 2012 Link to this post


    In order to have your RadCalendar instance display the month view based on your selected date variable, you simply need to set the RadCalendar instance .FocusedDate property to your selected date variable.

    The FocusedDate property specifies the date that has focus. By default, RadCalendar uses the current date as the focused date. When the calendar shows more than one month (either in multi-view mode or with an enlarged day matrix), the focused date appears by default in the first month that the calendar shows. When the calendar is in multi-view mode, you can change which view contains the focused date by setting the FocusedDateColumn and FocusedDateRow properties.

    Here's server-side code that sets RadCalendar1 Month View based on the RadDatePicker date input's current;y selected date when the "Apply on server" button gets clicked.:

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI.Calendar.View;
    public partial class Default : System.Web.UI.Page
            //private int DayOfMonth;
            private DateTime selectedDate;
            private string backgroundColor = String.Empty;
            private DateTime startDate;
            private DateTime endDate;
            private void Page_Load(object sender, System.EventArgs e)
                if (!Page.IsPostBack)
                    RadDatePicker1.SelectedDate = DateTime.Today;
                selectedDate = (DateTime)RadDatePicker1.SelectedDate;
                backgroundColor = ColorList.Items[ColorList.SelectedIndex].Value;
            protected override void OnPreRender(EventArgs e)
                base.OnPreRender (e);
                RadCalendar1.FocusedDate = selectedDate;
                startDate = ((MonthView) RadCalendar1.CalendarView).MonthStartDate;
                endDate = ((MonthView) RadCalendar1.CalendarView).MonthEndDate;
            protected void CustomizeDay(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
                DateTime CurrentDate = e.Day.Date;
                if (startDate <= CurrentDate && CurrentDate <= endDate)
                    if (CurrentDate == selectedDate)
                        TableCell currentCell = e.Cell;
                        currentCell.Style["background-color"] = backgroundColor;

    See attached image.

    Hope this helps!
Back to Top