Repeater控件中添加删除与修改按钮方法
1: <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("id") %>' OnClientClick="return confirm('是否删除')" OnClick="Del" >删除</asp:LinkButton>
//修改同理
2:在后台中添加删除方法
public void Del(object sender,EventArgs e)
{
int id = Convert.ToInt32((sender as LinkButton).CommandArgument);
//把sender由object转换成LinkButton后获取CommandArgument的值
new xh.shop.DAL.link().Delete(id);
Repeater1.DataSource = new xh.shop.DAL.link().GetList("");
Repeater1.DataBind();
}
3 后台修改方法
protected void mod(object sender, EventArgs e)
{
int id = Convert.ToInt32((sender as Button).CommandArgument);
string canmae = ((sender as Button).NamingContainer.FindControl("txtcaname") as TextBox).Text;
//找到文本框的方法
xh.shop.Model.categroy model = new xh.shop.DAL.categroy().GetModel(id);
if (model!=null)
{
model.caname = canmae;
new xh.shop.DAL.categroy().Update(model);
Response.Redirect(Request.Url.ToString());
}
}