开发者

linq to XML as a gridview datasource

开发者 https://www.devze.com 2023-01-13 07:16 出处:网络
I\'m trying to get all the ema开发者_如何学Cil nodes for the customers in the sample xml and binding it to a grid.I can\'t seemt to get past the linq query!

I'm trying to get all the ema开发者_如何学Cil nodes for the customers in the sample xml and binding it to a grid. I can't seemt to get past the linq query!

Sample XML:

<group>
<customer>
<email>testing@testing.com></email>
</customer>
<customer>
<email>testing2@testing.com</email>
</customer>
</group>

var query = from result in xml.Elements("customer")
select new
{
email = xml.Element("email").Value
};

gridview1.DataSource = query;
gridview1.DataBind();


Elements() will only get you direct children, therefore, if your xml variable is an XDocument, its only direct children (according to the little sample) are group elements.

Try:

var query = from result in xml.Descendants("customer")
select new { email = result.Element("email").Value };
0

精彩评论

暂无评论...
验证码 换一张
取 消