2012-01-05 3 views
2

Здравствуйте, я использую linq для заполнения gridview информацией из xml из codebehind. Я хотел бы заказать мою Grid в соответствии с одним из моих элементов в xml («элемент значения»), но не могу понять, как это сделать. Есть идеи?LINQ: Order By Anonymous Тип

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