asp.net 页面用DataGrid显示xml文件内容的排序问题,请大家帮忙!
想要在页面DataGrid中按id的降序显示xml的内容,使用以下方法,但显示的仍然是升序排列的内容,不知道问题出在哪里.
方法:
————————————————————————————————
private void ReadXML()
{
String url = Server.MapPath( "backupDBLog.xml ");
StreamReader sRead = new StreamReader(url,System.Text.Encoding.GetEncoding( "UTF-8 "));
XmlDataDocument datadoc = new XmlDataDocument();
datadoc.DataSet.ReadXml(sRead);
DataView dv = new DataView(datadoc.DataSet.Tables[0]);
dv.Sort = "id desc ";
this.DataGrid1.DataSource = datadoc.DataSet;
this.DataGrid1.DataBind();
datadoc = null;
sRead.Close();
}
————————————————————————————————
xml文件:
-------------------------------
<?xml version= "1.0 "?>
<!--database backup-->
<DBLog>
<log id= "2007713132838 ">
<backupFileName> 2007713132838 </backupFileName>
<backupTime> 2007-7-13 13:28:38 </backupTime>
<downloadTime> 2007-7-17 9:19:12 </downloadTime>
<downloadNum> 20 </downloadNum>
<downloadIP> 127.0.0.1 </downloadIP>
<operators> 管理员 </operators>
</log>
<log id= "2007713132840 ">
<backupFileName> 2007713132840 </backupFileName>
<backupTime> 2007-7-13 13:28:40 </backupTime>
<downloadTime> 2007-7-16 15:35:26 </downloadTime>
<downloadNum> 13 </downloadNum>
<downloadIP> 127.0.0.1 </downloadIP>
<operators> 管理员 </operators>
</log>
<log id= "2007713132953 ">
<backupFileName> 2007713132953 </backupFileName>
<backupTime> 2007-7-13 13:29:53 </backupTime>
<downloadTime> 2007-7-16 13:10:42 </downloadTime>
<downloadNum> 12 </downloadNum>
<downloadIP> 127.0.0.1 </downloadIP>
<operators> 管理员 </operators>
</log>
</DBLog>
------解决方案--------------------this.DataGrid1.DataSource = datadoc.DataSet;
这里改下就可以了
this.DataGrid1.DataSource = dv;