代码如下
        public static List<SelectListItem> CreateSelect<T>(this IList<T> t, string text, string value)
        {
            List<SelectListItem> l = new List<SelectListItem>();
            foreach (var item in t)
            {
                var propers = item.GetType().GetProperty(text);
                var valpropers = item.GetType().GetProperty(value);
                l.Add( new SelectListItem{Text=propers.GetValue(item,null).ToString(), Value=valpropers.GetValue(item,null).ToString()} );
            }
            return l;
        }
 
c#List泛型数据扩展,把List<>型数据格式化成List<SelectListItem>,用来作dropdownlist的数据,布布扣,bubuko.com
c#List泛型数据扩展,把List<>型数据格式化成List<SelectListItem>,用来作dropdownlist的数据
原文:http://blog.csdn.net/asp89007342/article/details/38379571