Avatar of Saroj13
Saroj13
 asked on

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

Hi ,

I have this code to fill the Month, Day and Year dropdownlist in asp.net 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();
                this.ddlMonth.Items.Add(list);
            }
            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;
C#ASP.NET

Avatar of undefined
Last Comment
disrupt

8/22/2022 - Mon
dj_alik

see solution
asp .net day month dropdown list box creation
http://forums.asp.net/t/1134942.aspx/1
Saroj13

ASKER
Its written in vb.net. i need something in c#
ASKER CERTIFIED SOLUTION
dj_alik

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
disrupt

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes