How to populate month name in DropDownList in ASP.NET

Posted by SheoNarayan under ASP.NET category on | Points: 40 | Views : 22521
In order to populate the month name in the DropDownList, you can use below code snippet.

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()));

In the above code, commented code shows how to write abbreviated month name too, so in case you do not want to show the full month name in the dropdown, use GetAbbreviatedMonthName method.


Comments or Responses

Posted by: Chvrsri on: 10/26/2010 Level:Silver | Status: [Member] [Moderator] [MVP] | Points: 10
Nice Post!!!
Posted by: SheoNarayan on: 10/26/2010 Level:HonoraryPlatinum | Status: [Administrator] | Points: 10
Thanks Chvrsri, keep reading !
Posted by: on: 1/10/2012 Level:Starter | Status: [Member] | Points: 10
sir please tell me how to bind dayname in DropDownList

Login to post response