Click here to Skip to main content
Click here to Skip to main content

Dynamic DropDownList with Month Names

, 13 Jul 2007
Rate this:
Please Sign up or sign in to vote.
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
        /// <span class="code-SummaryComment"><summary>
</span>        /// fills a dropDownlist with month list.
        /// <span class="code-SummaryComment"></summary>
</span>        /// <param name="MyddlMonthList" />The DropDown List that will Hold the Months.</param />
        /// <param name="SetCurruntMonth" />if set to <span class="code-SummaryComment"><c>true</c> the Current Month will be selected.</param />
</span>        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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ZeroDev
Chief Technology Officer
Jordan Jordan
Life is really simple, but we insist on making it complicated

Comments and Discussions

 
GeneralMy vote of 4 PinmemberDiwakar Gupta16-Dec-11 1:53 
GeneralGood Job PinmemberPrakash Varun 201014-Jul-10 19:33 
GeneralOther option Pinmemberchristianfdiazm27-Nov-09 6:24 
GeneralHere is a VB Version PinmemberMr. Hef2-Oct-07 5:35 
GeneralRe: Here is a VB Version PinmemberZeroDev3-Oct-07 7:08 
GeneralSome changes in your code PinmemberEduardo Calixto13-Jul-07 3:24 
GeneralRe: Some changes in your code PinmemberZeroDev13-Jul-07 3:30 
GeneralThanks PinmemberZeroDev13-Mar-07 21:37 
GeneralExactly what I wanted Pinmembertoxaq13-Mar-07 10:06 
GeneralGood Job!!! PinmemberDomingo M. Asuncion6-Mar-07 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 13 Jul 2007
Article Copyright 2006 by ZeroDev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid