如何在 GridView C# asp.net 中显示 JavaScript 确认对话框并运行函数?

当我删除 GridView 行时,我想显示 JavaScript 确认对话框并运行一个函数。你是怎样做的?


类似的东西:


protected void GridViewActivities_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if(e.Row.RowType == DataControlRowType.DataRow)

        {

            LinkButton lb = (LinkButton)e.Row.FindControl("LinkButton1");

            lb.Attributes.Add("onClick", "return confirm('You are sure?'); + MyFunction()");

        }

    }


四季花海
浏览 112回答 1
1回答

慕尼黑8549860

如果你想根据确认框结果运行你的函数,试试这个代码protected void GridViewActivities_RowDataBound(object sender, GridViewRowEventArgs e)    {        if(e.Row.RowType == DataControlRowType.DataRow)        {            LinkButton lb = (LinkButton)e.Row.FindControl("LinkButton1");            lb.Attributes.Add("onclick", "var result = confirm('You are sure?'); if(result) { MyFunction(); } return true; ");        }    }如果您想在不考虑确认框结果的情况下运行您的函数,请尝试以下代码:protected void GridViewActivities_RowDataBound(object sender, GridViewRowEventArgs e)    {        if(e.Row.RowType == DataControlRowType.DataRow)        {            LinkButton lb = (LinkButton)e.Row.FindControl("LinkButton1");            lb.Attributes.Add("onclick", "confirm('You are sure?'); MyFunction(); return true; ");        }    }
打开App,查看更多内容
随时随地看视频慕课网APP