开发者

Trying to bind results from linq-xml query to gridview

开发者 https://www.devze.com 2023-01-07 04:10 出处:网络
I am attempting to bind linq-to-xml query to a gridview. I have the following XML 开发者_如何学C <?xml version=\"1.0\" encoding=\"utf-8\" ?>

I am attempting to bind linq-to-xml query to a gridview.

I have the following XML

开发者_如何学C <?xml version="1.0" encoding="utf-8" ?> 
 <thesaurus xmlns="x-schema:tsSchema.xml">
 <diacritics_sensitive>0</diacritics_sensitive>
    <expansion>
        <sub>satellite navigation</sub>
        <sub>sat-nav</sub>
        <sub>Sat Nav</sub>
        <sub>tom tom</sub>
    </expansion>
    <expansion>
        <sub>Car</sub>
        <sub>Vehicle</sub>
        <sub>Motor</sub>
        <sub>Wheels</sub>
        <sub>Ride</sub>
    </expansion>
 </thesaurus>

I use the following Linq Query

        var query = from term in xDocumentTerms.Elements(tns + "thesaurus").Elements(tns + "expansion").Elements(tns + "sub")
                    where term.Value == val
                    select term.Parent.Descendants().ToList<XElement>();


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

Which returns data, however binds the count and the capacity of the List opposed to what I would really like the XElement.Value.


i think the problem is that you are not binding to a list of XElements but to a query producing a list of lists of XElement due to the last ().ToList < XElement > (); being applied to each item selected not the whole query.

If in doubt change var to List < XElement > and debug from there;

0

精彩评论

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