Pages

Wednesday 22 January 2014

How to populate month name in DropDownList in ASP.NET

DropDownList code

<asp:DropDownList ID="dropDown1" runat="server"></asp:DropDownList> 



Namespace to use

using System.Globalization; 



Code behind

DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null);

        for (int i = 1; i < 13; i++)

        {

            //Response.Write(info.GetAbbreviatedMonthName(i) + "<br />");

            dropDown1.Items.Add(new ListItem(info.GetMonthName(i), i.ToString()));

        }

No comments:

Post a Comment