Disable all dates except current date in calender control using c#

Description


You can disable all dates except current date programmatically.You can also change the background color dyanamically.

Calender control

<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" ></asp:Calendar>


Code Behind

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date > DateTime.Now.Date || e.Day.Date < DateTime.Now.Date)
{
e.Cell.Enabled = false; //disable current date

}
else
{
e.Cell.BackColor = System.Drawing.Color.Blue;//You can change color of the current date
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: