ASP.NET Datalist Sorting (XMl Source)
I am populating a datalis开发者_JS百科t 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?
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();
精彩评论