Click here to Skip to main content
6,595,444 members and growing! (17,871 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Dynamic DropDownList with Month Names

By ZeroDev

Method to Fill the a DropDownList with Month Names and set the Current Month Selected
C# 2.0, Windows, .NET 2.0, ASP.NET, Visual Studio, WebForms, IE 6.0, Dev
Posted:26 Aug 2006
Updated:13 Jul 2007
Views:29,483
Bookmarked:13 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
14 votes for this article.
Popularity: 3.27 Rating: 2.85 out of 5
3 votes, 21.4%
1
1 vote, 7.1%
2

3
6 votes, 42.9%
4
4 votes, 28.6%
5
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ZeroDev


Member
Life is really simple, but we insist on making it complicated
Occupation: Chief Technology Officer
Location: Jordan Jordan

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
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    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Jul 2007
Editor:
Copyright 2006 by ZeroDev
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project