xml 结构是这样的:
<?xml version="1.0" encoding="GB2312" ?>
+ <DataMenu>
- <ProductItem ProductID="Big001" ProductName="产品名称" RechargeURL="http://www.163.com/"KeyWord="简介" >
<catItem catID="Big001_010" ParPrice="10.00" />
<catItem catID="Big001_030" ParPrice="30.00" />
</ProductItem>
</DataMenu>
我读取的方式: private System.Xml.XmlTextReader GetXmlDocument(string Url)
{
System.Xml.XmlTextReader Reader = new System.Xml.XmlTextReader(Url);
return Reader;
} protected void Bind()
{
System.Data.DataSet DS = new System.Data.DataSet();
DS.ReadXml(this.GetXmlDocument("http://www.xxx.com/service/productList.aspx"));
gvList.DataSource = DS.Tables[0];
gvList.DataBind();
}
我的问题:这样GridView不能读取
catItem 的数据?以前没有做过这种xml 知道的兄弟指点一下
<?xml version="1.0" encoding="GB2312" ?>
+ <DataMenu>
- <ProductItem ProductID="Big001" ProductName="产品名称" RechargeURL="http://www.163.com/"KeyWord="简介" >
<catItem catID="Big001_010" ParPrice="10.00" />
<catItem catID="Big001_030" ParPrice="30.00" />
</ProductItem>
</DataMenu>
我读取的方式: private System.Xml.XmlTextReader GetXmlDocument(string Url)
{
System.Xml.XmlTextReader Reader = new System.Xml.XmlTextReader(Url);
return Reader;
} protected void Bind()
{
System.Data.DataSet DS = new System.Data.DataSet();
DS.ReadXml(this.GetXmlDocument("http://www.xxx.com/service/productList.aspx"));
gvList.DataSource = DS.Tables[0];
gvList.DataBind();
}
我的问题:这样GridView不能读取
catItem 的数据?以前没有做过这种xml 知道的兄弟指点一下
你不是要读取XML吗,怎么把aspx传进去了
wc.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData("http://www.xxx.com/service/productList.aspx");
string xml = Encoding.Default.GetString(pageData);
且:GridView已经能够读取了ProductItem 的数据
但是:不能读取catItem 的数据
注:http://www.xxx.com/service/productList.aspx aspx页面就是xml文件
且:GridView已经能够读取了ProductItem 的数据
但是:不能读取catItem 的数据
你使用DS.ReadXml方法
你这个XML结构会返回两个DataTable一个是ProductItem
一个是catItem 而绑定到GridView的数据是DS.Tables[0];
也就是ProductItem 你根本没用到catItem 啊你想如何绑定??
跟踪调试下你的DataSet就知道了
那应该用什么方法catItem 呢
你的Grid上到底要绑定ProductItem 还是catItem ??如果是ProductItem 你就用现在的方式如果是catItem 你就用DS.Tables[1]就可以了
现在就是
ProductItem
catItem 都要捆绑到Grid上
需要重新创建一个DataTable,将需要的数据加入,绑定新的DataTable。好象没有其它更好的办法了。或者可以按主从表浏览-详情的模式来处理
你Grid是什么样子的?主从式的么?能不能整张图片看看?这跟XML就没关系了主要是你DataTable的样式以及你Grid的样式