Tuesday, June 29, 2010

How to disable day of asp.net calender based on criteria - Asp.net

Inorder to disable perticular date in calender, we can use three properties of  day render event arguement.
  • e.Cell.Enabled
  • e.Day.IsSelectable
  • e.Cell.BackColor = Color.Gray
Example
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script runat="server">
        List<DateTime> validDays = new List<DateTime>();
        protected override void OnLoad(EventArgs e)
        {
            validDays = this.FindValidDates();
        }
 
        private List<DateTime> FindValidDates()
        {
            int month = DateTime.Now.Month;
            int year = DateTime.Now.Year;
            for (int i = 1; i < 31; i += 2)
                validDays.Add(new DateTime(year, month, i));
            return validDays;
        }
 
        protected void DayRander(object sender, DayRenderEventArgs e)
        {
            if (!validDays.Exists(x => x == e.Day.Date))
            {
                e.Cell.Enabled = false;
                e.Day.IsSelectable = false;
                e.Cell.BackColor = Color.Gray;
            }
        }        
    </script>
</head>
<body>
    <form id="form1" runat="server">
 
    <div>
        <asp:Calendar runat="server" ID="calDates" OnDayRender="DayRander" />
    </div>
    </form>
</body>
</html>
 

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...