Click here to Skip to main content
13,089,818 members (49,654 online)
Rate this:
Please Sign up or sign in to vote.
See more:
please let me give an idea regarding calendar control using dropdown list for month and year details
Posted 28-Sep-11 22:09pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Here I'm providing link for generating calender with dropdownlist controls

I hope this links helps you to understand calender control details

And I tried some code for generating months in dropdown list

<form id="form1" runat="server">
      <td>Year :
          <asp:DropDownList ID="ddlyear" runat="server">

      <td>Month :
          <asp:DropDownList ID="ddlmonth" runat="server" AutoPostBack="True"

      <td>Date :
          <asp:DropDownList ID="ddldate" runat="server">


And the code behind file contains following code

protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)

        for (int i = 1; i <= 12; i++)
             System.Globalization .DateTimeFormatInfo nm=new System.Globalization.DateTimeFormatInfo ();
             ddlmonth.Items.Add (new ListItem (nm.GetMonthName(i).ToString (),i.ToString ()));

        for (int i = 1900; i <= System.DateTime.Now.Year; i++)

            ddlyear.Items.Add (new ListItem( i.ToString (),i.ToString ()));


protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
    for (int i = 1; i <= System.DateTime.DaysInMonth(int.Parse(ddlyear.SelectedValue), int.Parse(ddlmonth.SelectedValue)); i++)
          ddldate .Items.Add (new ListItem (i.ToString (),i.ToString ()));


In the above code I filled days based on month selected by user.

If you can use jquery it is easy fill dynamically with asynchronous requests.
or use Ajax update panels also

All the Best
Manikandan Sekar 22-Feb-13 4:48am
Its working fine only but what the matter of fact is you checked the months but you didnt checked the leap years that is when we select a leap year in the dropdown list means it wont show the February 29days instead of that it shows only 28 days. but it is worthful code
Muralikrishna8811 22-Feb-13 9:04am
Hi Manikandan,

Thanks for your observation.

That is my mistake I just typed month id instead of year .And no need to check whether leap year or not in manually DaysInMonth() method checks internally thn returns corresponding days.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100