higlighting current week in the calendar on pageload

2 posts, 0 answers
  1. Regeesh Joseph
    Regeesh Joseph avatar
    55 posts
    Member since:
    May 2010

    Posted 23 Jul 2010 Link to this post

    Hai,

    I want to get the current week to be highlighted on the radcalendar. How to get it done?

    Plz help me.

    Thanks & regards,
    Regeesh Joseph
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jul 2010 Link to this post

    Hello Rageesh,

    The following code snippet will be useful for you to achieve this.

    ASPX:
    <telerik:RadCalendar ID="RadCalendar2" runat="server" OnDayRender="RadCalendar2_DayRender">
    </telerik:RadCalendar>

    C#:
    int weekNumber;
       protected void Page_Load(object sender, EventArgs e)
       {
           weekNumber = GetNumber(DateTime.Now.Date);
       }
     protected void RadCalendar2_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
       {
           if (GetNumber(e.Day.Date) == weekNumber)
           {
               e.Cell.Style.Add("background-color", "Aqua");
           }
       }
       public static int GetNumber(DateTime dtDate)
       {
           System.Globalization.CultureInfo ciGetNumber = System.Globalization.CultureInfo.CurrentCulture;
           int returnNumber = ciGetNumber.Calendar.GetWeekOfYear(dtDate, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
           return returnNumber;
       }

    Thanks,
    Princy.
Back to Top