無法按日期排列列表。如何顯示按日期排序的數據?數據未按日期排序
XDocument doc = XDocument.Load(Server.MapPath("file.xml"));
IEnumerable<XElement> items = from item in doc.Descendants("item")
orderby Convert.ToDateTime(item.Attribute("lastChanges").Value) descending
where item.Attribute("x").Value == 1
select item;
Repeater1.DataSource = items;
Repeater1.DataBind();
XML文件如下所示:
<root>
<items>
<item id="1" lastChanges="15-05-2010" x="0" />
<item id="2" lastChanges="16-05-2010" x="1" />
<item id="3" lastChanges="17-05-2010" x="1" />
</items>
</root>
您的linq查詢甚至不會爲我運行。我得到一個構建錯誤,指出'=='不能應用於'string'和'int'類型的操作數。你運行這個代碼? – CoderDennis 2010-05-19 15:34:07
我通過在where子句中使用「1」而不是1修復了構建錯誤。之後,結果如預期。 – CoderDennis 2010-05-19 15:42:53