views:

13

answers:

1

I am populating a datalist control with a simple xml source. It displays some Dates in whatever order they are displayed in the xml file. I want them to be sorted before they are displayed in the Datalist. Can this be done?

A: 

Depends on how you load the xml, if you load the XML into a dataset you can sort before binding.

DataSet myDataSet = new DataSet();
myDataSet.ReadXML("mydata.xml");
DataView myDataView = new DataView(myDataSet.Tables[0]);
myDataView.Sort = "mySortField ASC"; //or DESC

myDataListControl.DataSource = myDataView;
myDataListControl.DataBind();
JDT