LINQ返回IList,绑定到ComboBox
//构造"自定义通用代码"数据集
Infos<MM_TYDMInfo> CustomTYDMInfos = new Infos<MM_TYDMInfo>();
MM_TYDMInfo item = new MM_TYDMInfo();
item.LBID = (decimal)enumTydmlb;
item.DMMC = "无";
item.ID = 0;
CustomTYDMInfos.DataMember.Add(item);
item = new MM_TYDMInfo();
item.LBID = (decimal)enumTydmlb;
item.DMMC = "一级";
item.ID = 1;
CustomTYDMInfos.DataMember.Add(item);
item = new MM_TYDMInfo();
item.LBID = (decimal)enumTydmlb;
item.DMMC = "二级";
item.ID = 2;
CustomTYDMInfos.DataMember.Add(item);
item = new MM_TYDMInfo();
item.LBID = (decimal)enumTydmlb;
item.DMMC = "三级";
item.ID = 3;
CustomTYDMInfos.DataMember.Add(item);
item = new MM_TYDMInfo();
item.LBID = (decimal)enumTydmlb;
item.DMMC = "四级";
item.ID = 4;
CustomTYDMInfos.DataMember.Add(item);
//用LINQ根据LBID属性从自定义数据集读取数据
var query = from tydminfos in CustomTYDMInfos
where tydminfos.LBID == (decimal)enumTydmlb
select tydminfos;
//转换成IList<T>
IList<MM_TYDMInfo> TYDMList = query.ToList();
//绑定数据
this.DataSource = TYDMList;
//设置默认选择
if (TYDMList.Count > 0)
this.SelectedIndex = 0;