How to disable particular Day of a Week in ASP.Net Calendar control?
Read my previous snippet How to disable Weekends(Saturday and Sunday) in ASP.Net Calendar control? which discussed on disabling the weekend dates.
Sometimes, we may have requirements to block or disable a particular day of a week in the caledar control. The below little code snippet will help you to do that by using DayRender event of Calendar control. Set IsSelectable=false in Day Render event of the calendar control for every Monday. You can get the day of a week by using e.Day.Date.DayOfWeek property which returns a enum of type DayOfWeek. Doing like this will disable all the Monday for any month in your Calendar control.
Refer the below code, ASPX <asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>
CodeBehind protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { if (e.Day.Date.DayOfWeek == DayOfWeek.Monday) { e.Day.IsSelectable = false; } }
To disable any other day, just change the DayOfWeek enum on right handside expression in the if condition.
Once executed the user will not be able to select the dates that falls on that day. Happy Coding!!
|