Link to home
Start Free TrialLog in
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;
Avatar of dj_alik
dj_alik

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

ASKER

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

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