Gridview中 LinkButton删除以及自带删除

<asp:LinkButton ID="lbtnDel" OnClientClick="return confirm('删除新闻会连同其下评论一起删除,是否删除?')" OnClick="lbtnDel_Click" CommandArgument='<%#Eval("id") %>' runat="server">删除</asp:LinkButton>

 

protected void lbtnDel_Click(object sender, EventArgs s)
    {
        string id = ((LinkButton)sender).CommandArgument;
       bool b =  new NewsManager().Delete(id);      
        if (b)
        {
            BindNews();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('未知原因导致删除失败!');</script>");    
        }
    }

 

gridview改进自带删除

<asp:CommandField ShowDeleteButton="True" DeleteText="&lt;span id=&quot;de&quot; onclick=&quot;JavaScript:return confirm('确定删除吗?')&quot;&gt;删除&lt;/span&gt; " />

你可能感兴趣的:(GridView)