Click here to Skip to main content
Licence CPOL
First Posted 26 Aug 2006
Views 52,729
Bookmarked 18 times

Dynamic DropDownList with Month Names

By ZeroDev | 13 Jul 2007 | Unedited contribution
Method to Fill the a DropDownList with Month Names and set the Current Month Selected
3 votes, 18.8%
1
1 vote, 6.3%
2

3
7 votes, 43.8%
4
5 votes, 31.3%
5
2.90/5 - 16 votes
μ 2.93, σa 2.71 [?]
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>
        /// <param name="MyddlMonthList" />The DropDown List that will Hold the Months.</param />
        /// <param name="SetCurruntMonth" />if set to <c>true</c> the Current Month will be selected.</param />
        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

Member
Life is really simple, but we insist on making it complicated

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberDiwakar Gupta2:53 16 Dec '11  
GeneralGood Job PinmemberPrakash Varun 201020:33 14 Jul '10  
GeneralOther option Pinmemberchristianfdiazm7:24 27 Nov '09  
GeneralHere is a VB Version PinmemberMr. Hef6:35 2 Oct '07  
GeneralRe: Here is a VB Version PinmemberZeroDev8:08 3 Oct '07  
GeneralSome changes in your code PinmemberEduardo Calixto4:24 13 Jul '07  
GeneralRe: Some changes in your code PinmemberZeroDev4:30 13 Jul '07  
GeneralThanks PinmemberZeroDev22:37 13 Mar '07  
GeneralExactly what I wanted Pinmembertoxaq11:06 13 Mar '07  
GeneralGood Job!!! PinmemberDomingo M. Asuncion16:31 6 Mar '07  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 13 Jul 2007
Article Copyright 2006 by ZeroDev
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid