Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear fellows.I have to restrict access or selection to the date of any previous Day,Month,Year in the Calendar Control except today's or any day(s) after tomorrow


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

{

    if(e.Day.Date.ToShortDateString() <= DateTime.Now.ToShortDateString())

    {

        e.Cell.BackColor=ColorTranslator.FromHtml("#a9a9a9");

        e.Day.IsSelectable=false;

    }

}

this approach just change the back color and not disabling selection.I first extracted the days in integers separately because if also has some errors.Anyways;it doesn't work
C#
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        DateTime pastday = e.Day.Date;
        DateTime date = DateTime.Now;
        int year = date.Year;
        int month = date.Month;
        int day = date.Day;
        DateTime today = new DateTime(year, month, day);
        if (pastday.CompareTo(today) < 0)
        {
            e.Cell.BackColor = System.Drawing.Color.Gray;
            e.Day.IsSelectable = false;
        }
    }

that approach didn't work as well
Posted
Updated 8-Jul-13 0:25am
v2

Dont use this control.

Use this![^]
 
Share this answer
 
C#
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
     {
         if (e.Day.Date < DateTime.Now)
         {
               e.Cell.Text = e.Day.Date.Day.ToString();
               e.Cell.BackColor = System.Drawing.Color.Gray;
               e.Day.IsSelectable = false;

         }
     }
 
Share this answer
 
v3
Refer to this link

ASP.NET AJAX Calendar Extender–Tips and Tricks[Tip-6][^]

You can find lots of customizations,that would be beneficial for future use also.

Regards..:laugh:
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900