2012-01-05 75 views
2

你好,我正在使用LINQ来填充gridview与从代码隐藏xml的信息。我想根据xml中的一个元素(“value元素”)来订购我的Grid,但无法弄清楚如何做到这一点。有任何想法吗?LINQ:订购者匿名类型

gvResourceEditor.DataSource = (From resElem In resourceElements.Elements("data") _ 
    Select New With { _ 
    .Key = resElem.Attribute("name").Value, _ 
    .Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _ 
    .Comment = If(resElem.Element("comment") IsNot Nothing, HttpUtility.HtmlEncode(resElem.Element("comment").Value), String.Empty) _ 
     }).OrderBy(?????) 

回答

3
gvResourceEditor.DataSource = _ 
    From resElem In resourceElements.Elements("data") _ 
    Select Data = New With { _ 
     .Key = resElem.Attribute("name").Value, _ 
     .Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _ 
     .Comment = If(resElem.Element("comment") IsNot Nothing, HttpUtility.HtmlEncode(resElem.Element("comment").Value), String.Empty) _ 
    } Order By Data.Value 
+0

完美!谢谢 :) – Arno 2012-01-05 12:51:57