Wednesday, January 20, 2010

Get Months English Name

How to populate your dropdownlist with months english name in a fast way?






Imports System.Globalization

Dim intloop As Integer

For intloop = 1 To 12
   
      dropdownlist1.Items.Add(New ListItem(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames(intloop - 1), intloop))

Next     





PS:
- Result = a drop down list of months with 1,2,3...12 as value, and January, February, ..... December as Text
- Remember to import class "System.Globalization"
- A New ListItem has to be declared each time when adding item into a drop down list. The first value is the text of the drop down  list item, while the second value is the value of the item.

No comments:

Post a Comment