Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
please let me give an idea regarding calendar control using dropdown list for month and year details
Posted 28-Sep-11 23:09pm

1 solution

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

Solution 1

Hi,
 
Here I'm providing link for generating calender with dropdownlist controls
 
http://www.codeproject.com/KB/scripting/JavaScriptCalendar.aspx
 
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">
    <div>
      <table>
        <tr>
          <td>Year : 
              <asp:DropDownList ID="ddlyear" runat="server">
              
          </td>
          <td>Month : 
              <asp:DropDownList ID="ddlmonth" runat="server" AutoPostBack="True" 
                  onselectedindexchanged="ddlmonth_SelectedIndexChanged">
              
          </td>
          <td>Date : 
              <asp:DropDownList ID="ddldate" runat="server">
              
          </td>
        </tr>
      </table>
    </div>
    </form>
 
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)
    {
        ddldate.Items.Clear();
        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
  Permalink  
v3
Comments
Manikandan Sekar at 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 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150305.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2015
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