- Mar 16 Fri 2012 00:12
Design Patterns(設計模式) 自我整理
- Feb 22 Wed 2012 12:55
(轉貼) 學習 LINQ to SQL
- Jul 15 Sun 2012 00:40
DropDownList擴充-列舉(enum)使用
讓enum變成view來使用好像滿頻繁的,記錄一下擴充dropdownlist
public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name, string selectValue) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue)); } public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name,string selectValue, object htmlAttributes) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue), htmlAttributes); } public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name,string selectValue, IDictionary<string, object> htmlAttributes) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue), htmlAttributes); } public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name,string selectValue, string optionLabel) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue), optionLabel); } public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name, string selectValue, string optionLabel, object htmlAttributes) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue), optionLabel, htmlAttributes); } public static MvcHtmlString DropDownEnumList<T>(this HtmlHelper htmlHelper, string name,string selectValue, string optionLabel, IDictionary<string, object> htmlAttributes) where T : struct, IConvertible { return htmlHelper.DropDownList(name, GetSelectEnumListItems<T>(selectValue), optionLabel, htmlAttributes); } public static IEnumerable<SelectListItem> GetSelectEnumListItems<T>(string selectValue) where T : struct, IConvertible { List<SelectListItem> items = new List<SelectListItem>(); foreach (var e in Enum.GetNames(typeof(T))) { string val = ((int)Enum.Parse(typeof(T), e)).ToString(); var selectlistItem = new SelectListItem() { Text = e, Value = val }; if (!string.IsNullOrWhiteSpace(selectValue) && (val == selectValue)) { selectlistItem.Selected = true; } items.Add(selectlistItem); } return items; }
- Apr 10 Tue 2012 23:16
[C#] 區分 abstract、virtual、override 和 new
- Apr 06 Fri 2012 15:34
[jQuery] 2個ListBoxs 做搬移處理。
- Mar 31 Sat 2012 18:41
[轉貼] 23種設計模式的趣味解釋
- Mar 10 Sat 2012 15:20
[C#] InterFace-介面、接口 (二)
- Mar 10 Sat 2012 15:04
[C#] InterFace-介面、接口 (一)
- Mar 07 Wed 2012 01:23
[NH]NHibernate介紹