[转] 为GridView删除添加确认对话框

① -----Template way-----
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton runat="server" CausesValidation="False" CommandName="Delete"
Text
="删除" OnClientClick='return confirm("Are you sure you want to delete this record?");'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

② -----RowDeleting method-----
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    Response.Write(
"<script>window.confirm('确定删除吗?');</script>");
}

③ -----RowDataBound method-----
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    
if (e.Row.RowType == DataControlRowType.DataRow)
    
{
        ((LinkButton)e.Row.Cells[
4].Controls[0]).Attributes.Add("onclick""return confirm('确实要删除该记录吗?')");
    }

}
posted @ 2008-03-26 14:51  temptation  阅读(356)  评论(1编辑  收藏  举报