這裏是我的解決方案,這是非常相似@傑西褐色的溶液(公認的答案)
VB.NET:
在全局函數類:
Public Shared Function GetMonthList() As Generic.Dictionary(Of String, String)
Dim months As New Generic.Dictionary(Of String, String)()
For m As Int32 = 1 To 12
months.Add(String.Format("{0:0#}", m), CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(m))
Next
Return months
End Function
在ASPX頁面:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ddMonth.DataSource = GlobalFunctions.GetMonthList()
ddMonth.DataValueField = "Key"
ddMonth.DataTextField = "Value"
ddMonth.DataBind()
End Sub
這個實現是VB.NET,因爲這種情況發生這個webapp使用的是(遺留),但是非常感謝C#中的例子(我的首選語言),我在這裏發佈VB.NET以幫助VB.NET社區。
有趣的問題,我有同樣的問題一次。 +1 – pyrocumulus 2009-05-01 17:43:37
你需要本地化這個值嗎? – Greg 2009-05-01 17:46:23
本地化不是必需條件,但是如果它已經存在於本地化狀態中,它不會受到傷害。 – 2009-05-01 17:55:18