Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net calendar date range

I have two calendars. What I am trying to implement is based on the date selected in the first calendar, the date range in the second one will be from calendar1.selectedDate + 1 until indefinite.

So any of the dates < calendar1.selectedDate should not be selectable in calendar2.

How to set a range for a calendar, or at least set the start date?

asp:calendar has many attributes but just cannot find what I am looking for.

Thanks in advance.

like image 211
sd_dracula Avatar asked Dec 28 '25 20:12

sd_dracula


1 Answers

Try this

For the second calendar control

<asp:Calendar ID="Calendar2" runat="server" ondayrender="Calendar2_DayRender"></asp:Calendar>

on DayRender event

    protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
    {
        DateTime dte = Calendar1.SelectedDate;
        if (e.Day.Date <= dte)
        {
            e.Day.IsSelectable = false;
            e.Cell.ForeColor = System.Drawing.Color.Gray;
        }
    }
like image 185
Prashanth Thurairatnam Avatar answered Dec 31 '25 10:12

Prashanth Thurairatnam