I have created a very simple dropdownbox:
<asp:DropDownList ID="MonthDropDown" runat="server" AutoPostBack="True">
</asp:DropDownList>
Code Behind:
MonthDropDown.DataSource = Enumerable.Range(1, 12);
MonthDropDown.SelectedIndex = DateTime.Now.Month;
MonthDropDown.DataBind();
Is there any way to get the MonthDropDown(my dropdownbox) to display name of month, instead of the numeric value of the month. I’m thinking it could be something like
DateTimeFormatInfo.CurrentInfo.GetMonthName(MonthDropDown.SelectedIndex)?
This is culture-specific of course, so look for it under the
CultureInfoclass:You can set the month names as the values in the ListBox:
You can also use keys/values if you still want the selected value to be the index: