How I can filter, sort xml before binding it to a repeater?
I have a xml data which I need to filter on the basis of querystring and then sort it before binding it into repeater.
I know how to bind xml with repeater and its working fine too but I am facing problem in filtering based on query string and sorting.
Any help would really be appreciated?
My XML is like this
<Categories>
<Category>
<Title>Food<Title>
<Date>12/1/2009</Date>
<Duration>12/1/2009-12/1/2011</Duration>
<Description>Who is hungry</Description>
<Category>
<Categories>
I want to sort by date and duration. I also want to filter by title (based on the querystring).
LINQ to XML is probably the way to go here, but if you’re stuck in 2.0-land, this will return an
XPathNodeIteratorthat provides your filtered and sorted XML:Note that if you only needed to filter (not sort), you could use the simpler, declarative
TemplateControl.XPathSelectright in your aspx template (the example in the linked documentation is pretty close to your scenario).XPathNodeIteratorimplementsIEnumerable, so you can bind a repeater directly to it. To get values in child nodes, use theTemplateControl.XPathmethod, like this (you could also get attributes or grand-child nodes, etc., with appropriate XPath expressions):