.net Repeater内部的按钮事件代码demo(Repeater内button的删除事件)
<asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <tr height="60" style="border-bottom:1px #ccc solid; 100%"> <td ><%#Eval("ID")%></td> <td ><img src="<%# Eval("pingtu ") %>" width="80" height="50" /></td> <td ><%#Eval("pingming")%></td> <td ><%# Convert.ToDateTime(Eval("addTime")).ToString("yyyy-MM-dd")%></td> <td > <a href="editcp.aspx?ID=<%#Eval("ID") %>">编辑</a> <asp:Button ID="Button1" runat="server" Text="删除" CommandArgument='<%#Eval("ID") %>' OnClientClick="return confirm('确认删除?')" onclick="Button1_Click" /> </td> </tr> </ItemTemplate> </asp:Repeater>
protected void Button1_Click(object sender, EventArgs e) { Button btn = sender as Button; int id = int.Parse(btn.CommandArgument); //删除操作 string sql = "delete from tb_chanpin where ID ='" + id + "' "; BaseClass.ExecNonQuery(sql); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language=javascript>window.location.href=window.location.href; </script>"); }