data is not getting ordered by date

Posted by raging_boner on Stack Overflow See other posts from Stack Overflow or by raging_boner
Published on 2010-05-19T11:30:35Z Indexed on 2010/05/23 19:51 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

Can't get list sorted by date. How to show data ordered by date?

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 file looks like this:

<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>

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Xml