Calendar control - disabling past dates.

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.
 
M

Mark Rae

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top