Calendar Control

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi Guys,

Does anybody know how to restrict the dates that will be shown in a calendar
control? For example, I only would like to display dates between 1 June
2004 to 1 December 2004.

Is this possible?

Cheers

Steve
 
You need to handle the DayRender event, and disable the dates outside the
range.

private void Calendar1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
DateTime minDate = new DateTime(2004, 6, 1);
DateTime maxDate = new DateTime(2004, 12, 1);
DateTime currentDate = e.Day.Date;

if ((DateTime.Compare(currentDate, minDate) == -1) ||
(DateTime.Compare(maxDate, currentDate) == -1))
{
e.Day.IsSelectable = false;
e.Cell.Enabled = false;
}
}

Hope this helps,

Mun
 
Back
Top