Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Dynamic DropDownList with Month Names

0.00/5 (No votes)
13 Jul 2007 1  
Method to Fill the a DropDownList with Month Names and set the Current Month Selected
how to Creat a DropDownList with Month Names
#region Method to Fill the a DropDownList with Month Names and set the Current Month Selected
        /// <summary>

        /// fills a dropDownlist with month list.

        /// </summary>

        /// The DropDown List that will Hold the Months.

        /// if set to <c>true</c> the Current Month will be selected.

        public void GetMyMonthList(DropDownList MyddlMonthList,bool SetCurruntMonth)
        {
            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();
                MyddlMonthList.Items.Add(list);
            }
            if (SetCurruntMonth == true)
            {
                MyddlMonthList.Items.FindByValue(DateTime.Now.Month.ToString()).Selected = true;
            }
            

        }
        #endregion
thats it Happy Coding

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here