Link to home
Start Free TrialLog in
Avatar of Saroj13

asked on

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

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;
Avatar of dj_alik

see solution
asp .net day month dropdown list box creation
Avatar of Saroj13


Its written in i need something in c#
Avatar of dj_alik

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial