What is the best way to code up a Month and Year drop down list for ASP.NET?

后端 未结 8 1531
北荒
北荒 2020-12-16 00:31

I have an internal application that I needs to have a drop down list for two date type elements: Month and Year. These values are not in

8条回答
  •  被撕碎了的回忆
    2020-12-16 01:20

    You could use this to get a list of all the Month names and loop through it.

    CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
    

    You can use it like this...using the index of the Month as the value for your dropdown

    var months = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
    for (int i = 0; i < months.Length; i++)
    {
         ddl.Items.Add(new ListItem(months[i], i.ToString()));
    }
    

提交回复
热议问题