LINQ:订单匿名类型 [英] LINQ: Order By Anonymous Type

查看:134
本文介绍了LINQ:订单匿名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用LINQ,以填补从codebehind的XML信息的GridView。我想根据我的XML(值元素)内容之一订购我的网格,但无法弄清楚如何做到这一点。有任何想法吗?

  gvResourceEditor.DataSource =(从resElem在resourceElements.Elements(数据)_
    选择新用{_
   。重点= resElem.Attribute(名)。价值_
   .value的= HttpUtility.HtmlEn code(resElem.Element(值)。值),_
   的.comment = IF(resElem.Element(意见)状态并没有没什么,HttpUtility.HtmlEn code(resElem.Element(意见)。值)的String.Empty)_
      })排序依据(?????)


解决方案

  gvResourceEditor.DataSource = _
   从resElem在resourceElements.Elements(数据)_
     选择Data =新增功能{_
       。重点= resElem.Attribute(名)。价值_
       .value的= HttpUtility.HtmlEn code(resElem.Element(值)。值),_
       的.comment = IF(resElem.Element(意见)状态并没有没什么,HttpUtility.HtmlEn code(resElem.Element(意见)。值)的String.Empty)_
     }顺序按Data.Value

Hello I am using linq to fill a gridview with the information from an xml from codebehind. I would like to order my Grid according to one of my elements in the xml ("value element") but can't figure out how to do this. Any ideas?

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

解决方案

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

这篇关于LINQ:订单匿名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆