【问题标题】:LINQ: Order By Anonymous TypeLINQ:按匿名类型排序
【发布时间】:2012-01-05 12:30:15
【问题描述】:

您好,我正在使用 linq 使用来自代码隐藏的 xml 的信息填充网格视图。我想根据 xml 中的一个元素(“值元素”)来订购我的 Grid,但不知道如何做到这一点。有任何想法吗?

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

【问题讨论】:

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


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多