Repeater控件中添加删除与修改按钮方法

1:   删除

//修改同理

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());
            }
        }

转载于:https://www.cnblogs.com/luqingsong/archive/2011/01/03/1924995.html

你可能感兴趣的:(Repeater控件中添加删除与修改按钮方法)