JavaScript写在GridView控件rowdeleting事件确认删除 [英] Write javascript for confirm delete in gridview rowdeleting event

查看:335
本文介绍了JavaScript写在GridView控件rowdeleting事件确认删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我删除从GridView的行为我所用GridView控件的默认删除命令字段。在单击时,GridView的行删除命令被炒鱿鱼,​​并选定行被删除。所有好的至今。

I am deleting a row from gridview for which i have used gridview's default delete command field. On clicking, the gridview row deleting command gets fired and the selected row gets deleted. All good till now.

但在此之前该行被删除,我需要设置的确认信息给用户。在单击确定按钮的行应该被删除别人没有(对点击取消按钮)。

But before the row gets deleted, i need to set confirmation message to user. On clicking of OK button the row should get deleted else not (on click of cancel button).

我有code为;

return confirm('Are you sure to delete?');

不过,这工作得很好,如果有一个LinkBut​​ton(而不是命令字段),因为我可以很容易写的LinkBut​​ton的OnClick事件,并可能在GridView的RowDataBound事件添加属性。

But this works fine if there is a linkbutton (instead of command field) as i could easily write on OnClick event of linkbutton and could add the attributes in Gridview RowDataBound event.

如何同样将工作命令的现场删除按钮?请指导!

How the same would work for command's field delete button? Please guide!

谢谢!

推荐答案

本文介绍了如何做的正是你所需要的:

This article explains how to do exactly what you need:

HTTP://www.$c$cproject.com/KB/ web表单/ Gridview_Delete_confirmLS.aspx

这里是你需要做的code:

And here is the code you need to do it:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // loop all data rows
        foreach (DataControlFieldCell cell in e.Row.Cells)
        {
           // check all cells in one row
           foreach (Control control in cell.Controls)
           {
                // Must use LinkButton here instead of ImageButton
                // if you are having Links (not images) as the command button.
                ImageButton button = control as ImageButton;

                if (button != null && button.CommandName == "Delete")
                    // Add delete confirmation
                    button.OnClientClick = "return confirm('Are you sure you want to delete this record?');";
            }
        }
    }
}

这篇关于JavaScript写在GridView控件rowdeleting事件确认删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆