更新时间:2023-02-14 11:36:46
您无法将IEnumerable绑定到数据源,但有许多对象可以。大多数都比DataTable简单得多。
列表怎么样:// 您不需要此方法。只是ToList()的演示
public 列表< t> ToList( this IEnumerable< t> source){
return source.ToList();
}
< / t > < / t >
希望有所帮助^ _ ^
Andy
How to bind IEnumerable object to combobox datasource? or How to convert IENumerable object to datatable ot dataset?
IEnumerable<alist> objList = objservice.GetList(1,combobox1.SelectedValue.ToString(), "A", 72, 523 , null);
if (dsDetails == null || dsDetails.Tables[0].Rows.Count == 0)
{
DataRow drDetails = dsDetails.Tables[0].NewRow();
drDetails["BName"] = "No Records";
drDetails["BCode"] = 0;
drDetails.Tables[0].Rows.InsertAt(drDetails , 0);
}
else if (dsDetails.Tables[0].Rows.Count > 1)
{
DataRow drDetails = dsDetails.Tables[0].NewRow();
drDetails["BName"] = "<-- Select -->";
drDetails["Code"] = 0;
dsDetails.Tables[0].Rows.InsertAt(drDetails, 0);
}
//cb1.DisplayMember = "BName";
//cb1.ValueMember = "BCode";
//cb1.DataSource = dsDetails.Tables[0];
cb1.DisplayMember = "Description";
cb1.ValueMember = "ACode";
cb1.DataSource = objApproverlist;
I want to use objApproverlist instead of dsGetails to cb1.datasource
You can't bind an IEnumerable to a datasource, but there are many object that can. Most are far simpler than a DataTable.
What about a List://You don't need this method. Just a demo of ToList() public List<t> ToList(this IEnumerable<t> source){ return source.ToList(); } </t></t>
Hope that helps ^_^
Andy