日期:2014-05-18 浏览次数:20470 次
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" EnableViewState="True">
<ItemTemplate>
<td>商品价格: <%# DataBinder.Eval(Container.DataItem, "Price")%> </td>
<td> <asp:Label ID="Label1" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem, "GoodsId")%>' Visible="false"> </asp:Label> </td>
<td> <asp:LinkButton id="lbtn1" runat="server" Text="删除" CommandName="del" OnClientClick="return confirm('确定删除吗?');"> </asp:LinkButton> </td>
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { Label lab = (Label)e.Item.FindControl("Label1"); string goodsid = lab.Text; string strCon = ConfigurationManager.ConnectionStrings["InfoWebConnectionString"].ConnectionString; SqlConnection Conn = new SqlConnection(strCon); Conn.Open(); SqlCommand cmd = new SqlCommand("DELETE FROM Goods WHERE GoodsId = '" + goodsid + "'", Conn); cmd.ExecuteNonQuery(); Conn.Close(); } }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { Label lab = (Label)e.Item.FindControl("Label1"); string goodsid = lab.Text; string strCon = ConfigurationManager.ConnectionStrings["InfoWebConnectionString"].ConnectionString; SqlConnection Conn = new SqlConnection(strCon); Conn.Open(); SqlCommand cmd = new SqlCommand("DELETE FROM Goods WHERE GoodsId = '" + goodsid + "'", Conn); cmd.ExecuteNonQuery(); Conn.Close(); } // <-- 这里重新绑定数据源 }
------解决方案--------------------
二楼的方法正确
------解决方案--------------------
我认为你的错误是没有绑定,最重要的是
Repeater1.DataSource = ds;
Repeater1.DataBind();
这两句话