LINQ:按匿名类型排序

时间:2012-01-05 12:30:16

标签: asp.net vb.net linq sql-order-by

您好我正在使用linq使用来自codebehind的xml中的信息填充gridview。我想根据xml中的一个元素(“值元素”)来命令我的网格,但无法弄清楚如何执行此操作。有任何想法吗?

    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(?????)

1 个答案:

答案 0 :(得分: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