Newbie10 Newbie10 - 19 days ago 5
ASP.NET (C#) Question

Disable Days: 5 days after current date on Calendar

I have a reservation system. On my page there is a calendar where the client will choose the arrival date, but I want to limit the client's selection of date, he can only choose the 5th day from the current date and onward.
Ex: Current date is Nov. 14, 2016 he can only select from Nov. 20, but the dates from Nov. 14-Nov.19 are disabled.

this is my current code on my calendar

protected void ArrivalCalendar_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now)
{
e.Day.IsSelectable = false;
e.Cell.BackColor = System.Drawing.Color.LightGray;
e.Cell.Enabled = false;
}
}

Answer

You have to add days to your current date DateTime.Now.AddDays(5), see below code

protected void ArrivalCalendar_DayRender(object sender, DayRenderEventArgs e)
    {
        if (e.Day.Date < DateTime.Now.AddDays(5))
        {
            e.Day.IsSelectable = false;
            e.Cell.BackColor = System.Drawing.Color.LightGray;
            e.Cell.Enabled = false;
        }
    }
Comments