troubleshooting Question

How to fill day, month and year dropdownlist and c#?

Avatar of Saroj13
Saroj13 asked on
4 Comments1 Solution6809 ViewsLast Modified:
Hi ,

I have this code to fill the Month, Day and Year dropdownlist in and c#. How to fill day dropdown so that it will have appropriate days in the dropdown for selected month and year.
Currently day dropdown is not having the appropriate days for the selected month and year

 DateTime month = Convert.ToDateTime("1/1/2000");
            for (int i = 0; i < 12; i++)
                DateTime NextMont = month.AddMonths(i);
                ListItem list = new ListItem();
                list.Text = NextMont.ToString("MMMM");
                list.Value = NextMont.Month.ToString();
            ddlMonth.Items.FindByValue((DateTime.Now.Month).ToString()).Selected = true;

         //   ddlDate.Items.Add(new ListItem("Day", "Day"));
         //   ddlDate.SelectedIndex = 0;

            int totalDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
            for (int intLoop = 1; intLoop <= totalDays; intLoop++)
                ddlDay.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString()));

            ddlDay.Items.FindByValue((DateTime.Now.Day).ToString()).Selected = true;

          //  ddlYear.Items.Add(new ListItem("Year", "Year"));
         //   ddlYear.SelectedIndex = 0;

            int intYearName = 2008;
            for (int intLoop = intYearName; intLoop <= Convert.ToInt32(DateTime.Now.Year); intLoop++)
                ddlYear.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString()));

            ddlYear.Items.FindByValue((DateTime.Now.Year).ToString()).Selected = true;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros