Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Gauge for SharePoint
Search :       Advanced Search »
Home » ASP.NET » Web Server Calendar Control in ASP.NET 2.0

Web Server Calendar Control in ASP.NET 2.0

Most of the time we come across a situation when we need to extend the existing functionality of any control. So, in the following article we will see that how to extend the calendar control.

Author Rank :
Page Views : 3524
Downloads : 63
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Calender.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

The Calendar control is based on the .NET Framework DateTime object, and you can display any date between the years 0 and 9999 A.D.In the following article you will find that you can utilize the existing control as per you requirement.

In Visual Studio 2005 changing the template is quit easy as compare to MS VS 2003.You can see the templates below:-



 

 

 

After selecting the template for calender, editor will generate the following code for you:

<asp:Calendar ID="calSource" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px"  DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px" OnSelectionChanged="calSource_SelectionChanged">
            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
            <SelectorStyle BackColor="#FFCC66" />
            <OtherMonthDayStyle ForeColor="#CC9966" />
            <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
            <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>

In the same way add other controls also

 

<asp:DropDownList ID="drpMonthCal" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpCalMonth_SelectedIndexChanged" Width="101px">

        </asp:DropDownList>&nbsp;

        <asp:DropDownList ID="drpYearCal" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpCalYear_SelectedIndexChanged" Width="104px">

        </asp:DropDownList>

<asp:Label ID="lblDate" runat="server" Text="Label" Width="390px"></asp:Label>

 

Now you are ready with the web page.So you can start with the implementation.

 

protected void Page_Load(object sender, EventArgs e)

    {

         //Hide the title of the calendar control

        calSource.ShowTitle = false;   

       //Populate month and year dropdown list boxes which

       //replace the original calendar title

        if (!Page.IsPostBack)

        {   

            Populate_MonthddList();   

            Populate_YearddList();

        } 

        lblDate.Text = "Current date: " + calSource.TodaysDate;

    } 

    private void Populate_MonthddList()

    {

        drpMonthCal.Items.Add("January");

        drpMonthCal.Items.Add("February");

        drpMonthCal.Items.Add("March");

        drpMonthCal.Items.Add("April");

        drpMonthCal.Items.Add("May");

        drpMonthCal.Items.Add("June");

        drpMonthCal.Items.Add("July");

        drpMonthCal.Items.Add("August");

        drpMonthCal.Items.Add("September");

        drpMonthCal.Items.Add("October");

        drpMonthCal.Items.Add("November");

        drpMonthCal.Items.Add("December"); 

       // drpCalMonth.Items.FindByValue((objdate.Month.ToString())).Selected = true;

       // drpCalYear.Items.FindByValue(DateTime.Now.Month.ToString()).Selected = true;

    } 

    private void Populate_YearddList()

    {

        //Year list can be extended

        int intYear ;          

        for(intYear =Convert.ToInt16(DateTime.Now.Year) - 20;intYear<=DateTime.Now.Year + 20;intYear++)

        {  

             drpYearCal.Items.Add(Convert.ToString(intYear));

        }

        drpYearCal.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true; 

    }

    protected void calSource_SelectionChanged(object sender, EventArgs e)

    {

        if (calSource.SelectedDates.Count == 1)

            // If one date is selected, display it.

            lblDate.Text = "Selected date: " + calSource.SelectedDate;

        else

            // If multiple dates are selected, display them.

            lblDate.Text = "Selected dates: " + calSource.SelectedDates[0] + " to " + calSource.SelectedDates[calSource.SelectedDates.Count - 1]; 

    }

    protected void drpCalMonth_SelectedIndexChanged(object sender, EventArgs e)

    {

        calSource.TodaysDate =Convert.ToDateTime (drpMonthCal.SelectedItem.Value + " 1, " + drpYearCal.SelectedItem.Value);

    }

    protected void drpCalYear_SelectedIndexChanged(object sender, EventArgs e)

    {

        calSource.TodaysDate = Convert.ToDateTime(drpMonthCal.SelectedItem.Value + " 1, " + drpYearCal.SelectedItem.Value);

    }

 

After writing the code Run the application.

Now you will see the following output screen :-

 

 

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Sonu Chauhan
Sonu holds B. Sc. (Mathmatics, Physics & Statistics) and MCA (Master's of Computer Applications) degrees. Currently he is working with Merrill Lynch. India and has extensive experience in web technologies using .NET and SQL Reporting services. Sonu also has good hands on experience in Micorosoft Content Management Server.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
Where is the code???? by Aleem On February 20, 2007
your zip contains only sln file. There is not project.
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.