在asp.net中显示XML里所有id号的商品展示
时间:2011-12-11
来源:互联网
在编写代码里实现当id=xml里的id时 在另个网页的tabel里显示商品详细信息
DataShow(String id)方法可以不用看 是在网页中显示的信息 是正确的
因为当我把 string id = Request.QueryString["TypeId"].ToString();
改成id=311时 就显示了一个出来
但是我想实现两个都显示 用到了上面的段代码却显示不出来
请问有什么错的地方?
public partial class cp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
string id = Request.QueryString["TypeId"].ToString();
DataShow(id);
}
}
//方法参考
//方法参考
//方法参考
private void DataShow(String id){
DataSet ds=new DataSet();
FileStream fs=new FileStream(Server.MapPath("cp.xml"),FileMode.Open );
ds.ReadXml(fs);
for(int i=0;i<ds.Tables[0].Rows.Count;i++){
if(ds.Tables[0].Rows[i]["TypeId"].ToString()==id)
{
Label1.Text=ds.Tables[0].Rows[i]["Name"].ToString();
Label2.Text=ds.Tables[0].Rows[i]["TypeId"].ToString();
Label7.Text=Label3.Text=ds.Tables[0].Rows[i]["PinPai"].ToString();
Label4.Text=ds.Tables[0].Rows[i]["Color"].ToString();
Label5.Text=ds.Tables[0].Rows[i]["OldPrice"].ToString();
Label6.Text=ds.Tables[0].Rows[i]["NewPrice"].ToString();
// IMG2.src=ds.Tables[0].Rows[i]["image"].ToString();
Label8.Text="型号为:"+Label2.Text+" "+Label1.Text+" "+ds.Tables[0].Rows[i]["introduct"].ToString();
}
}
fs.Close();
}
}
//xml参考
//xml参考
//xml参考
<product>
<Name>耐克运动鞋</Name>
<TypeID>311</TypeID>
<PinPai>耐克</PinPai>
<Color>白</Color>
<OldPrice>660</OldPrice>
<NewPrice>330</NewPrice>
<image>image/product_doine.gif</image>
<introduct>hao</introduct>
</product>
<product>
<Name>阿迪达包</Name>
<TypeID>312</TypeID>
<PinPai>耐克</PinPai>
<Color>白</Color>
<OldPrice>660</OldPrice>
<NewPrice>330</NewPrice>
<image>image/product_doine.gif</image>
<introduct>hao</introduct>
</product>
在显示页面有这样几段代码我也看不懂
<td>
<a href='cp.aspx?TypeId=<%#DataBinder.Eval(Container.DataItem,"TypeID") %> '>
<img src='<%#DataBinder.Eval(Container.DataItem,"image") %>'/>
如果还有什么代码要贴的可以跟我说
DataShow(String id)方法可以不用看 是在网页中显示的信息 是正确的
因为当我把 string id = Request.QueryString["TypeId"].ToString();
改成id=311时 就显示了一个出来
但是我想实现两个都显示 用到了上面的段代码却显示不出来
请问有什么错的地方?
public partial class cp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
string id = Request.QueryString["TypeId"].ToString();
DataShow(id);
}
}
//方法参考
//方法参考
//方法参考
private void DataShow(String id){
DataSet ds=new DataSet();
FileStream fs=new FileStream(Server.MapPath("cp.xml"),FileMode.Open );
ds.ReadXml(fs);
for(int i=0;i<ds.Tables[0].Rows.Count;i++){
if(ds.Tables[0].Rows[i]["TypeId"].ToString()==id)
{
Label1.Text=ds.Tables[0].Rows[i]["Name"].ToString();
Label2.Text=ds.Tables[0].Rows[i]["TypeId"].ToString();
Label7.Text=Label3.Text=ds.Tables[0].Rows[i]["PinPai"].ToString();
Label4.Text=ds.Tables[0].Rows[i]["Color"].ToString();
Label5.Text=ds.Tables[0].Rows[i]["OldPrice"].ToString();
Label6.Text=ds.Tables[0].Rows[i]["NewPrice"].ToString();
// IMG2.src=ds.Tables[0].Rows[i]["image"].ToString();
Label8.Text="型号为:"+Label2.Text+" "+Label1.Text+" "+ds.Tables[0].Rows[i]["introduct"].ToString();
}
}
fs.Close();
}
}
//xml参考
//xml参考
//xml参考
<product>
<Name>耐克运动鞋</Name>
<TypeID>311</TypeID>
<PinPai>耐克</PinPai>
<Color>白</Color>
<OldPrice>660</OldPrice>
<NewPrice>330</NewPrice>
<image>image/product_doine.gif</image>
<introduct>hao</introduct>
</product>
<product>
<Name>阿迪达包</Name>
<TypeID>312</TypeID>
<PinPai>耐克</PinPai>
<Color>白</Color>
<OldPrice>660</OldPrice>
<NewPrice>330</NewPrice>
<image>image/product_doine.gif</image>
<introduct>hao</introduct>
</product>
在显示页面有这样几段代码我也看不懂
<td>
<a href='cp.aspx?TypeId=<%#DataBinder.Eval(Container.DataItem,"TypeID") %> '>
<img src='<%#DataBinder.Eval(Container.DataItem,"image") %>'/>
如果还有什么代码要贴的可以跟我说
作者: q379271395 发布时间: 2011-12-11
<a href='cp.aspx?TypeId=<%#DataBinder.Eval(Container.DataItem,"TypeID") %> '>
意思是把TypeID自带的值进行绑定,生成一个链接
结果可能是
<a href='cp.aspx?TypeId=311'>
<a href='cp.aspx?TypeId=312'>
这样的
<img src='<%#DataBinder.Eval(Container.DataItem,"image") %>'/>
是显示图片,图片的src书数据源中的image字段
意思是把TypeID自带的值进行绑定,生成一个链接
结果可能是
<a href='cp.aspx?TypeId=311'>
<a href='cp.aspx?TypeId=312'>
这样的
<img src='<%#DataBinder.Eval(Container.DataItem,"image") %>'/>
是显示图片,图片的src书数据源中的image字段
作者: net_lover 发布时间: 2011-12-11
另外,显示详细内容不用for循环,直接DataTable.Select 方法即可
DataRow[] foundRows = ds.Tables[0].Select("TypeId=" + id.ToString());
if(foundRows.Length>0)
{
Label1.Text=foundRows[0]["Name"].ToString();
.........
}
另外,如果你的TypeId有重复的,则需要循环
并且写
Label1.Text += foundRows[i]["Name"].ToString();
DataRow[] foundRows = ds.Tables[0].Select("TypeId=" + id.ToString());
if(foundRows.Length>0)
{
Label1.Text=foundRows[0]["Name"].ToString();
.........
}
另外,如果你的TypeId有重复的,则需要循环
并且写
Label1.Text += foundRows[i]["Name"].ToString();
作者: net_lover 发布时间: 2011-12-11
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28