Click here to Skip to main content
15,917,321 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               ddlMonth.DataSource = Enumerable.Range(1, 12).Select(a => new
               {
                   MonthName = DateTimeFormatInfo.CurrentInfo.GetMonthName(a),
                   MonthNumber = a
                   //DataTextField = DateTimeFormatInfo.CurrentInfo.GetMonthName(a),
                   //DataValueField = a
               }
               );

               //If this code is not working then try the above code in the loop.
               ddlMonth.DataTextField = "MonthName";
               ddlMonth.DataValueField = "MonthNumber";

               ddlMonth.DataBind();
               ddlYear.DataSource = Enumerable.Range(DateTime.Now.Year - 99, 100).Reverse();
               ddlYear.DataBind();
               ddlday.DataSource = Enumerable.Range(1, DateTime.DaysInMonth(DateTime.Now.Year, Convert.ToInt32(ddlMonth.SelectedValue)));
               ddlday.DataBind();
           }
       }
       protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
       {
           ddlday.DataSource = Enumerable.Range(1, DateTime.DaysInMonth(DateTime.Now.Year, Convert.ToInt32(ddlMonth.SelectedIndex + 1))); ddlday.DataBind();
       }
   }
Posted
Comments
Sandeep Mewara 30-Aug-12 5:04am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
ridoy 30-Aug-12 7:03am    
where is your question!??..what is your problem?

If you want the logic hope this will help you:http://stackoverflow.com/questions/9/calculating-age-from-birthday[^]
 
Share this answer
 
C#
System.DateTime date1 = new System.DateTime(2012, 1, 1);
System.DateTime date2 = System.DateTime.Now.Date;
// diff1 gets 242 days
System.TimeSpan diff1 = date2.Subtract(date1);
 
Share this answer
 
v2

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