I first tried using xmldatasource and found out that you can't sort it. If you try you will just receive error: "System.NotSupportedException: The data source does not support sorting."
GridView1.AllowSorting = true;
DataSet carsDataSet;
string filePath = Server.MapPath("App_Data/cars.xml");
carsDataSet = new DataSet();
//Read the contents of the XML file into the DataSet
carsDataSet.ReadXml(filePath);
GridView1.DataSource = carsDataSet.Tables[0].DefaultView;
GridView1.DataBind();
This will give me exception: "Exception Details: System.Web.HttpException: The GridView 'GridView1' fired event Sorting which wasn't handled."
My xml is like this:
<Cars>
<car>
<id>11</id>
<make>Audi</make>
<model>A4</model>
<price>39000</price>
</car>
</Cars>
So what is the best way to get around this issue? Or can I handle the sorting event somehow? Or would it be easier to load xml data to LINQ or something like that?