一尘不染

如何在详细信息视图中为命令字段添加删除确认提示?

sql

我想在用户尝试删除详细视图中的记录时提示用户进行确认吗?我有将showDeletebutton设置为true的命令。

我找到了如何确认gridview的方法,但是如何修改以匹配详细视图?

代码:

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;";
        }
    }
}
}

有人吗


阅读 166

收藏
2021-03-10

共1个答案

一尘不染

我找到了问题的答案。

我的答案:

 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;";

    }
}

无论如何,感谢您的帮助。

2021-03-10