两个自定义类的List,绑定到dropdownlist?
如:
List<T> list1 = bll.getlist();
List<T list2 = bll.getlist2();
这两个list如何集合在一起,赋给dropdownlist显示..谢谢.
[解决办法]
用这个方法AddRange
[解决办法]
list1.Union(list2);
[解决办法]
合并到一个list后绑定
[解决办法]
lz是不是想list1作为dropdownlist的text,list2是dropdownlist的value啊
List<string> list1 = new List<string>() { "a", "b", "c" };
List<string> list2 = new List<string>() { "1", "2", "3" };
var source = (from text in list1 from value in list2 where list1.IndexOf(text) == list2.IndexOf(value) select new ListItem() { Text = text, Value = value }).ToArray();
DropDownList1.DataSource = source;
DropDownList1.DataBind();
还是在dropdownlist里显示list1和list2的值的集合?
list1.AddRange(list2);
DropDownList1.DataSource = list1;
DropDownList1.DataBind();
[解决办法]