這種方法看起來很愚蠢,有點沉重;有沒有創造同樣的事情(它的MVC視圖下拉列表)在C#中創建月份下拉列表ASP.NET MVC
private List<KeyValuePair<int, string>> getMonthListDD
{
get
{
var dDur = new List<KeyValuePair<int, string>>();
dDur.Add(new KeyValuePair<int, string>(1, "January"));
dDur.Add(new KeyValuePair<int, string>(2, "Febuary"));
dDur.Add(new KeyValuePair<int, string>(3, "March"));
dDur.Add(new KeyValuePair<int, string>(4, "April"));
dDur.Add(new KeyValuePair<int, string>(5, "May"));
dDur.Add(new KeyValuePair<int, string>(6, "June"));
dDur.Add(new KeyValuePair<int, string>(7, "July"));
dDur.Add(new KeyValuePair<int, string>(8, "August"));
dDur.Add(new KeyValuePair<int, string>(9, "September"));
dDur.Add(new KeyValuePair<int, string>(10, "October"));
dDur.Add(new KeyValuePair<int, string>(11, "November"));
dDur.Add(new KeyValuePair<int, string>(12, "December"));
return dDur;
}
}
哇這麼多的方法對皮膚同兔;但我最喜歡這個,因爲它感覺乾淨。我可能會將它們全部推入大容量並查看哪些是最快的:op – 2010-05-26 10:00:26
這種寫法的唯一缺點是MonthNames(1月 - > 12月加上「空白」月份)有13個月的條目。這可能對您的UI有空白框是可以的,但如果您想要自定義選擇器標籤,那麼您需要通過修剪它來解決這個問題。 – Paul 2010-06-27 22:40:35
如果你想做@Paul提到的,你可以簡單地在Select語句 – snumpy 2011-05-24 19:39:20