Learn ASP.NET MVC How to's for free here.
Your details are safeBuyer's Satisfaction Contact Us
 Welcome Guest | Register | Login Why online training? | Buyers FAQs | Testimonials | Contact us 


Subscribe to Tutorials feed

Our Quality Professors

Our professors includes
Contact us for training ...

Technology Tags

ADO.NET AdRotator ASP.NET ASP.NET-AJAX Authentication-and-Authorization---LoginView BulletedList Button Caching Calendar Chart CheckBoxList Cookies CSharp CSS Cusotm-Control Debugging-and-Tracing DetailsView DropDownList-and-ListBox DropDownList-and--ListBox Error-handling FileUpload Forms-Authentication GridView HiddenField HTML HyperLink Image ImageButton ImageMap Javascript jQuery jQuery-Ajax jQuery-Attributes jQuery-effects jQuery-Effects jQuery-Events jQuery-How-to-Solution jQuery-Manipulations jQuery-Selectors jQuery-Traversing Label-and-Literal LinkButton ListView Localization-and-Globalization Login LoginName LoginStatus LoginStatus-and-LoginName-and-other-controls LoginView MasterPage Menu Meta-tags Panel PlaceHolder RadioButtonList Repeater Security Session-Management TextBox Themes-and-Skins Url-Routing User-Control Validations visual-studio Webconfig Working-with-Files-and-Folders

Search Tutorials

eg. asp.net


More ...


How to set the holidays in the Calendar control?

by: Itfunda Product Type: Tips and Tricks (Books) Technologies: ASP.NET  Calendar 

In case we want to display holidays in the calendar control dynamically from the server side, we can use this approach.

      <asp:Calendar runat="server" ID="Calendar1" BackColor="White" BorderColor="#3366CC"
            BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font- Names="Verdana"
            Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px" OnDayRender="AttachHolidays">
            <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
            <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
            <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
                Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
            <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
            <WeekendDayStyle BackColor="#CCCCCC" ForeColor="#333333" />
Code Behind
Dictionary<string, string> holidays = new Dictionary<string, string>();
protected void Page_Load(object sender, EventArgs e)
    // get the list of holiday from the database or any other source into the array

    holidays.Add("19", "DNF Days");
    holidays.Add("24", "ITF Days");
    holidays.Add("28", "ITFC Days");
protected void AttachHolidays(object sender, DayRenderEventArgs e)
    if (holidays.ContainsKey(e.Day.DayNumberText) && !e.Day.IsOtherMonth)
        // set the holday description with Literal control
        e.Cell.Controls.Add(new LiteralControl("<p>" +
        holidays[e.Day.DayNumberText] + "</p>"));
        // set the style
        e.Cell.BackColor = System.Drawing.Color.Green;
        e.Cell.ForeColor = System.Drawing.Color.Yellow;
        e.Cell.Font.Bold = true;
In the above code snippet, we have a Calendar control with different style set using its style related child elements. To set the holidays in the Celendar control, the list of holidays can be saved in the Dictionary object (key and value pair where key is the date and value is the description of the holiday), in real time project, you may get it from the database or some other data source. In OnDayRender event of the Calendar control, we have specified AttachHolidays method that fires when the Calendar control renders. In this method, the day of the holidays has been checked and current month date has been checked against the list of holidays in the Dictionary object and If
exists, a new Literal control has been added with the holiday description from the Dictionary object and then the background color, foreground color and font bold style have been changed.


This post is the part of following product

.NET How to Tips and Tricks (700+)

.NET How to Tips and Tricks (700+) This ".NET How to Tips and Tricks" contains solutions of hundreds of technical problems related with ASP.NET, ASP.NET MVC, SQL Serer, jQuery etc. that help you to develop real time .NET projects easily. It has following features
  • Video tutorials
  • Demo projects source code
  • eBook with to-the point explanations & output
prepared by Sheo Narayan (Ex Microsoft MVP).

 Latest tutorials

 Posts from Itfunda

  • CSS3 Online training
    In this training, you learn different types of Selectors, visual effects, web fonts, animation and working with Font service APIs. This is instructor led training and it is delivered by Sheo Narayan (Microsoft MVP).
    List Price: $75.00 Discount: 25.00% | Final Price: Rs 3375.00/$56.25
    More details ...

  • ASP.NET 4 Online Training with C#
    ASP.NET 4.0 using C# - A comprehensive online training on ASP.NET 4.0 using Visual C# 2013. This training gives you real time scenario based knowledge on C#, ASP.NET and ASP.NET AJAX that help you to work on any kind of web development projects in .NET technologies. This training is delivered by Mr. Sheo Narayan (Ex Microsoft MVP). Suitable for Windows developer or a complete freshers in the IT Industry who know HTML, CSS and JavaScript.
    List Price: $350.00 Discount: 25.00% | Final Price: Rs 13125.00/$262.50
    More details ...

Share this to:

Facebook Twitter LinkedIn Google+ Pinterest Email Addthis

About Us | Contact Us | Partners | Privacy Policy | Terms and Conditions | Buyer's FAQs | Seller's FAQs | Currency Converter | Go Top

Notice: If you found someone plagiarising our content/materials, kinldy let us know.

© SN ITFunda Services LLP. Site design and layout is copyright to SN ITFunda Services LLP.
Copying or duplicating or mimicking the site design and layout is prohibited and will be treated as a legal offence and will be prosecuted.
Logos, company, product, service or other names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 16102020 | 5/28/2024 3:08:36 AM