Hello All, We are going to start new batch from next week. message/call or mail us for more details.

24 February 2014

Holiday Calender List in ASP.Net C# - DotNet Brother

Well so most of the time as a developer we get requirement to develop a calender with holidays list, so here i have tried to explain this in very simple way. Just follow step by step to develop this. 

Open Microsoft Visual Studio --> Click File --> New --> Website --> Enter file Name --> OK 


Lets write few code on page Default.aspx page 



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Calendar ID="Calendar1" runat="server" Height="444px" Width="100%"OnDayRender="Calendar1_DayRender"
            OnSelectionChanged="Calendar1_SelectionChanged"OnVisibleMonthChanged="Calendar1_VisibleMonthChanged"
            DayNameFormat="Full" ForeColor="#000099" NextMonthText="">
            <DayHeaderStyle BackColor="#666699" ForeColor="Maroon" />
            <DayStyle BackColor="#CCCCCC" Font-Bold="True" Font-Italic="False" ForeColor="#000066" />
            <SelectedDayStyle BackColor="#9999FF" Font-Bold="True" ForeColor="Maroon" />
            <WeekendDayStyle BackColor="#999966" Font-Bold="True" ForeColor="#990000" />
        </asp:Calendar>
        <asp:Label ID="LabelAction" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Now write the below code in .cs page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
    Hashtable HolidayList;
    protected void Page_Load(object sender, EventArgs e)
    {
        HolidayList = Getholiday();
        Calendar1.Caption = "Calender";
        Calendar1.FirstDayOfWeek = FirstDayOfWeek.Monday;
        Calendar1.NextPrevFormat = NextPrevFormat.FullMonth;
        Calendar1.TitleFormat = TitleFormat.Month;
        Calendar1.ShowGridLines = true;
        Calendar1.DayStyle.Height = new Unit(50);
        Calendar1.DayStyle.Width = new Unit(150);
        Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Center;
        Calendar1.DayStyle.VerticalAlign = VerticalAlign.Middle;

        //Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.AliceBlue;
    }
    private Hashtable Getholiday()
    {
        Hashtable holiday = new Hashtable();
        holiday["1/1/2013"] = "New Year";
        holiday["1/5/2013"] = "Guru Govind Singh Jayanti";
        holiday["1/8/2013"] = "Muharam (Al Hijra)";
        holiday["1/14/2013"] = "Pongal";
        holiday["1/26/2013"] = "Republic Day";
        holiday["2/23/2013"] = "Maha Shivaratri";
        holiday["3/10/2013"] = "Milad un Nabi (Birthday of the Prophet";
        holiday["3/21/2013"] = "Holi";
        holiday["3/21/2013"] = "Telugu New Year";
        holiday["4/3/2013"] = "Ram Navmi";
        holiday["4/7/2013"] = "Mahavir Jayanti";
        holiday["4/10/2013"] = "Good Friday";
        holiday["4/12/2013"] = "Easter";
        holiday["4/14/2013"] = "Tamil New Year and Dr Ambedkar Birth Day";
        holiday["5/1/2013"] = "May Day";
        holiday["5/9/2013"] = "Buddha Jayanti and Buddha Purnima";
        holiday["6/24/2013"] = "Rath yatra";
        holiday["8/13/2013"] = "Krishna Jayanthi";
        holiday["8/14/2013"] = "Janmashtami";
        holiday["8/15/2013"] = "Independence Day";
        holiday["8/19/2013"] = "Parsi New Year";
        holiday["8/23/2013"] = "Vinayaka Chaturthi";
        holiday["9/2/2013"] = "Onam";
        holiday["9/5/2013"] = "Teachers Day";
        holiday["9/21/2013"] = "Ramzan";
        holiday["9/27/2013"] = "Ayutha Pooja";
        holiday["9/28/2013"] = "Vijaya Dasami (Dusherra)";
        holiday["10/2/2013"] = "Gandhi Jayanti";
        holiday["10/17/2013"] = "Diwali & Govardhan Puja";
        holiday["10/19/2013"] = "Bhaidooj";
        holiday["11/2/2013"] = "Guru Nanak Jayanti";
        holiday["11/14/2013"] = "Children's Day";
        holiday["11/28/2013"] = "Bakrid";
        holiday["12/25/2013"] = "Christmas";
        holiday["12/28/2013"] = "Muharram";
        return holiday;
    }
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        if (HolidayList[e.Day.Date.ToShortDateString()] != null)
        {
            Literal literal1 = new Literal();
            literal1.Text = "<br/>";
            e.Cell.Controls.Add(literal1);
            Label label1 = new Label();
            label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()];
            label1.Font.Size = new FontUnit(FontSize.Small);
            e.Cell.Controls.Add(label1);
        }
    }
    protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
    {
        LabelAction.Text = "Month changed to :" + e.NewDate.ToShortDateString();
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        LabelAction.Text = "Date changed to :" + Calendar1.SelectedDate.ToShortDateString();
    }
}

Press F5 and enjoy. 

4 comments:

  1. Great Job Sir,
    i am interested in taking your 60 hours .net training. Please reply me

    Ranjan
    Pune

    ReplyDelete
  2. If your programming is week so now don't worry VISIT HERE and get best classes for all programming languages. YOU CAN ALSO CALL AT : 9970600774

    ReplyDelete
  3. At Coepd (Center of Excellence for Professional Development) we practice Object-Oriented Programming concepts and mentor .Net Platform, C#.NET, ADO.NET which helps the attendees to build database-driven Web applications and Web Sites successfully. We also guide the attendees to develop web-based enterprise applications using ASP.NET and Visual Studio which comforts in developing the Web Services using .Net framework in Service-oriented Architecture. The Internship Program Also covers Frontend design technologies HTML, HTML5, CSS, CSS3, XML, Bootstrap, JQuery, Angular JS, and AJAX. Our collaborative ecosystem comprising of Partnerships with Software Companies enables real time software development life cycle experience.

    https://coepd.com/DotnetTraining.html

    ReplyDelete