Click here to Skip to main content
15,123,509 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please let me give an idea regarding calendar control using dropdown list for month and year details

1 solution


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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900