如何将Ienumerable()转换为字符串? [英] How to convert Ienumerable() to string?
问题描述
大家好,我有一个像这样的代码,iam将该字符串值绑定到dropdownlist。
string test = ds.Tables [0] .AsEnumerable() .Where(x => x.Field< int>(Id)== lbl.Text).Select(z => z.Field< string>(Description))。ToString();
Drpdwn.Items.Add(测试);
但执行时它会像这样绑定,
System.Data.EnumerableRowCollection'1 [System.String]
如何解决此问题?在此先感谢。 。
Hi all,i having a code like this and iam binding that string value to dropdownlist.
string test = ds.Tables[0].AsEnumerable().Where(x => x.Field<int>("Id") == lbl.Text).Select(z => z.Field<string>("Description")).ToString();
Drpdwn.Items.Add(test);
but when execution it binds like this,
System.Data.EnumerableRowCollection'1[System.String]
How to fix this?Thanks in Advance..
推荐答案
循环收集并将其添加到下拉项目。
Loops through the collection and add it to the dropdown items.
var items = ds.Tables[0].AsEnumerable().Where(x => x.Field("Id") == lbl.Text).Select(z => z.Field("Description")).ToList();
foreach(var i in items)
{
Drpdwn.Items.Add(i.ToString());
}
-KR
-KR
这篇关于如何将Ienumerable()转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!