repeater的删除事件

前台:

1)、添加repeater的事件属性 OnItemCommand="Repeater1_ItemCommand"

2)、添加删除按钮

<asp:LinkButton ID="lbtDelete" runat="server" CommandName="delete" CommandArgument='<%# Eval("id") %>'  Text="删除" OnClientClick="return confirm('你真的要删除吗?');">asp:LinkButton>

后台:

  1)、写repeater事件OnItemCommand

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)

    {

                if (e.CommandName == "delete") //删除操作

        {

            string que = "delete from [gz_gzsrb] where id='" +e.CommandArgument.ToString().Trim()+ "'";

            DBSqlHelp.ExecuteSql(3, que);//自己定义的一个DBSqlHelp类,执行sql语句]

        }

}

你可能感兴趣的:(asp.net学习总结)