How to populate a DropDownList with Culture-specific Month names

DateTimeFormatInfo.MonthNames is a useful property to fetch the culture-specific full names of the month. This property gets a string array containing the names of the month. Remember to add a reference to the System.Globalization namespace.

Here’s how to use this property and populate a DropDownList with month names:

C#

string[] names = DateTimeFormatInfo.CurrentInfo.MonthNames;
DropDownList1.DataSource = names;
DropDownList1.DataBind();

VB.NET

Dim names() As String = DateTimeFormatInfo.CurrentInfo.MonthNames
DropDownList1.DataSource = names
DropDownList1.DataBind()

OUTPUT

image



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: