Connecting Tech Pros Worldwide Forums | Help | Site Map

Calendar date blocking

Member
 
Join Date: Dec 2006
Posts: 39
#1: Sep 23 '08
Hi

I have to block all previous date in calendar. for that I have given coding as


protected void QuickCalendar_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
if ((e.Day.Date < DateTime.Now))
{
e.Day.IsSelectable = false;
}
}

But if i give that its blocking todays date also. I want todays date to be active.

Newbie
 
Join Date: Sep 2008
Location: Grey Ohio
Posts: 3
#2: Sep 23 '08

re: Calendar date blocking


Did you try an else?
if < today block
else is selectable = true
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#3: Sep 23 '08

re: Calendar date blocking


Hi there, i tried your code with one small change and it worked for me:

Expand|Select|Wrap|Line Numbers
  1. if ((e.Day.Date < DateTime.Now.Date))
  2. {
  3. e.Day.IsSelectable = false;
  4. }
This happens because the date returned from the control is at the very first second of the day i.e. midnight. DateTime.Now returns the current time including seconds thus, the start of the day is always less than the any other time of that day.
Reply