asp.net中的repeater控件不能连接数据库 5
html代码asp:RepeaterID="Repeater1"runat="server"><ItemTemplate><table><tr><tdcolspan="3...
html代码
asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="3"><%# DataBinder.Eval (Container.DataItem ,"商品名") %> </td>
</tr>
<tr>
<td rowspan="3"><img src="<%# DataBinder.Eval(Container.DataItem ,"图片") %>" />
</td>
<td>商品号:<%# DataBinder.Eval(Container.DataItem ,"商品号") %></td>
</tr>
<tr>
<td>价格:<%# DataBinder.Eval(Container.DataItem ,"价格") %></td>
</tr>
<tr>
<td>供应商:<%# DataBinder.Eval(Container.DataItem ,"供应商") %></td>
</tr>
</table>
</ItemTemplate>
后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default1 : System.Web.UI.Page
{
String SqlStr;
DataSet Ds = new DataSet();
DB db = new DB();
String Goods_ID;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
Goods_ID = Request.QueryString.Get(0).ToString().Trim();
SqlStr = "select * from 商品表 where 商品号="+Goods_ID;
Ds = db.GetDataTableBySql(SqlStr);
try
{
if (Ds.Tables[0].Rows.Count != 0)
{
this.Repeater1.DataSource = Ds.Tables[0].DefaultView;
this.Repeater1.DataBind();
Session["goodsid"] = Goods_ID;
}
}
catch (Exception)
{
Response.Write("<script>alert('无法连接数据数据,请检查!')</script>");
}
}
} 展开
asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="3"><%# DataBinder.Eval (Container.DataItem ,"商品名") %> </td>
</tr>
<tr>
<td rowspan="3"><img src="<%# DataBinder.Eval(Container.DataItem ,"图片") %>" />
</td>
<td>商品号:<%# DataBinder.Eval(Container.DataItem ,"商品号") %></td>
</tr>
<tr>
<td>价格:<%# DataBinder.Eval(Container.DataItem ,"价格") %></td>
</tr>
<tr>
<td>供应商:<%# DataBinder.Eval(Container.DataItem ,"供应商") %></td>
</tr>
</table>
</ItemTemplate>
后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default1 : System.Web.UI.Page
{
String SqlStr;
DataSet Ds = new DataSet();
DB db = new DB();
String Goods_ID;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
Goods_ID = Request.QueryString.Get(0).ToString().Trim();
SqlStr = "select * from 商品表 where 商品号="+Goods_ID;
Ds = db.GetDataTableBySql(SqlStr);
try
{
if (Ds.Tables[0].Rows.Count != 0)
{
this.Repeater1.DataSource = Ds.Tables[0].DefaultView;
this.Repeater1.DataBind();
Session["goodsid"] = Goods_ID;
}
}
catch (Exception)
{
Response.Write("<script>alert('无法连接数据数据,请检查!')</script>");
}
}
} 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询