Skip to main content
Email Password   helpLost your password?
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
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralHere is a VB Version Pin
Mr. Hef
6:35 2 Oct '07  
GeneralRe: Here is a VB Version Pin
ZeroDev
8:08 3 Oct '07  
GeneralSome changes in your code Pin
Eduardo Calixto
4:24 13 Jul '07  
GeneralRe: Some changes in your code Pin
ZeroDev
4:30 13 Jul '07  
GeneralThanks Pin
ZeroDev
22:37 13 Mar '07  
GeneralExactly what I wanted Pin
toxaq
11:06 13 Mar '07  
GeneralGood Job!!! Pin
Domingo M. Asuncion
16:31 6 Mar '07  


Last Updated 13 Jul 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009