Home > ASP.Net > Hide some days in the Calendar control

Hide some days in the Calendar control


Hi

try this example:-

— you may want to hide the days that is older than the current day :

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
    if (e.Day.Date.Date < DateTime.Now.Date)
    {
        e.Cell.Controls.Clear();
    }
}

— You may wonder how to hide some days in the ASP.NET standard calendar control. for example if you want to hide

the week end days ( Saturday and sunday)

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{

   if (e.Day.IsWeekend)
    {
        e.Cell.Controls.Clear();
    }
}

— Also Instead of hiding the days ,you can just make them un Selectables

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{

   if (e.Day.Date.Date < DateTime.Now.Date)
    {
        e.Day.IsSelectable = false;
        e.Cell.ToolTip = "sorry , You can't select this date ! ";
    }
}

Good Luck

Advertisements
Categories: ASP.Net Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: