如何添加删除确认提示命令字段的详细看法? [英] how to add delete confirmation prompt for command field in detail view?

查看:109
本文介绍了如何添加删除确认提示命令字段的详细看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当他试图在详细视图删除一条记录,提示用户确认?我已经申请命令中的ShowDeleteButton设置为true。

I want to prompt the user for confirmation when he tries to delete a record in a detail view? I have command filed in which showDeletebutton set to true.

我发现了怎么办确认为GridView的,但我怎么可以修改匹配的细节看法?

I found how to do the confirmation for gridview, but how can I modify to match detail view?

code:

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 = "if (!confirm('Are you sure " + 
                       "you want to delete this record?')) return;";
        }
    }
}
}

别人吗?

推荐答案

我找到了答案,我的问题。

I found the answer to my question.

我的回答:

 protected void DViewComputer_DataBound1(object sender, EventArgs e)
{
    int noRow = DViewComputer.Rows.Count - 1;//get the no of record

    if (noRow >0)
    {
        Button button = (Button)(DViewComputer.Rows[noRow].Cells[0].Controls[2]);

        // Add delete confirmation
        ((System.Web.UI.WebControls.Button)(button)).OnClientClick = "if (!confirm('Are you sure " +
                               "you want to delete this record?')) return;";

    }
}

反正感谢您的帮助球员。

Anyways thanks for your help guys.

这篇关于如何添加删除确认提示命令字段的详细看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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