<asp:LinkButton ID="lbtnDel" OnClientClick="return confirm('删除新闻会连同其下评论一起删除,是否删除?')" OnClick="lbtnDel_Click" CommandArgument='<%#Eval("id") %>' runat="server">删除</asp:LinkButton>
CommandArgument传多个参数: CommandArgument='<%#Eval("id")+","+Eval("interName") %>'
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="<span id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</span> " />