Calendar control - disabling past dates.

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Is there a way to disable past dates for a calendar control, or individual
date for that matter?


Any help is greatly appreciated.
 
Is there a way to disable past dates for a calendar control, or individual
date for that matter?

Dead easy - you need the DayRender method for this.

In your HTML:

<asp:Calendar ID="MyCalendar" runat="server"
OnDayRender="MyCalendar_DayRender" />


And in your code-behind:

protected void cal_DayRender(object source, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 18)
{
e.Cell.Controls.Clear();
e.Cell.Text = e.Day.DayNumberText;
e.Cell.BackColor = System.Drawing.Color.Gainsboro;
}
}

That will disable the 18th of every month. I'm sure you can figure the rest
out from that...
 
Back
Top