无法将数据导入列表框 [英] unable to get data to list box
本文介绍了无法将数据导入列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public SelectList GetAllprofsssinList()
{
var PList = new List< Profession&();
ds = dropdown.GetDropDownList();
for ( int record = 0 ; record < = ds.Tables [ 1 ]。Rows.Count - 1 ;记录++)
{
Profession objprof = new Profession();
动态行= ds.Tables [ 1 ]。行[记录];
objprof.ProfessionId = Convert.ToInt32(row [ ID]);
objprof.ProfessionName = Convert.ToString(row [DescriptionName];
}
SelectList testList = new SelectList( PList,ProfessionId;,ProfessionName;
return testList;
}
here in我的testList是null,但值是来到ProfessionId和ProfessionName
怎么办
解决方案
我想你错过了一行来填充那个list。
for ( int record = 0 ;记录< = ds.Tables [ 1 ]。Rows.Count - 1 ;记录++)
{
Profession objprof = 新专业();
动态行= ds.Tables [ 1 ] .Rows [记录];
objprof.ProfessionId = Convert.ToInt32(row [ ID]);
objprof.ProfessionName = Convert.ToString(row [DescriptionName];
PList.Add(objprof);
}
public SelectList GetAllprofsssinList()
{
var PList = new List<Profession&();
ds = dropdown.GetDropDownList();
for (int record = 0; record <= ds.Tables[1].Rows.Count - 1; record++)
{
Profession objprof = new Profession();
dynamic row = ds.Tables[1].Rows[record];
objprof.ProfessionId = Convert.ToInt32(row["ID"]);
objprof.ProfessionName = Convert.ToString(row[DescriptionName];
}
SelectList testList = new SelectList(PList,ProfessionId;, ProfessionName;
return testList;
}
here in my testList is null but the values are coming to ProfessionId and ProfessionName
what to do
解决方案
I think you missed one line to populate that list.
for (int record = 0; record <= ds.Tables[1].Rows.Count - 1; record++) { Profession objprof = new Profession(); dynamic row = ds.Tables[1].Rows[record]; objprof.ProfessionId = Convert.ToInt32(row["ID"]); objprof.ProfessionName = Convert.ToString(row[DescriptionName]; PList.Add(objprof); }
这篇关于无法将数据导入列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文