Geeks With Blogs
praveen pandey
You can either a buy a 3rd party control or write your own to get this working. And I was brave enough to write my own, so here is what I did.
The ASP.NET calendar control fires an event when you click on a day (DayRender ). Add a handler to this event
 
weeklyCalendar1.DayRender += new DayRenderEventHandler(weeklyCalendar1_DayRender);
 
 
in the Event Handler add the following code:
 
void weeklyCalendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date > DateTime.Today)
            {
                // e.Cell.BackColor = System.Drawing.Color.Gray;
                e.Day.IsSelectable = false;
            }
            DayOfWeek fd = (DayOfWeek)weeklyCalendar1.FirstDayOfWeek;
            DayOfWeek selectedday = weeklyCalendar1.SelectedDate.DayOfWeek;
 
            //Start Day of the week
            int dateDiffStartDay = selectedday - fd;
            if (dateDiffStartDay < 0)
            {
                dateDiffStartDay = 7 - Math.Abs(dateDiffStartDay);
            }
            DateTime FirstDate = weeklyCalendar1.SelectedDate.AddDays(-dateDiffStartDay);
 
            //LastDay of the week
            DateTime lastDate = weeklyCalendar1.SelectedDate.AddDays(-dateDiffStartDay).Date.AddDays(6);
 
 
            if (e.Day.Date >= FirstDate && e.Day.Date <= lastDate)
            {
                e.Cell.BackColor = System.Drawing.Color.Gray;
            }
            SelectedFirstDateOfTheWeek = FirstDate;
        }
 
Posted on Wednesday, June 30, 2010 9:15 AM ASP.NET | Back to top


Comments on this post: Selecting a Week in ASP.NET Calender Control

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Praveen Pandey | Powered by: GeeksWithBlogs.net