Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在gridview rowdatabound中设置onclientclick后未触发javascript_Javascript_Gridview_Rowdatabound - Fatal编程技术网

在gridview rowdatabound中设置onclientclick后未触发javascript

在gridview rowdatabound中设置onclientclick后未触发javascript,javascript,gridview,rowdatabound,Javascript,Gridview,Rowdatabound,我想启动一个javascript来确认删除该行 这是rowdatabound Private Sub GridSlide_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridSlide.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then

我想启动一个javascript来确认删除该行

这是rowdatabound

Private Sub GridSlide_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridSlide.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        DirectCast(e.Row.FindControl("LinkDelete"), LinkButton).Attributes.Add("OnClientClick", "javascript:DeleteSlide('" & Convert.ToString(e.Row.RowIndex) & "')")
    End If

End Sub
这是javascript

function DeleteSlide(var_row) {
    var blnResponse = null;
    var strMessage = '';
    try {
        strMessage = 'Are you sure you want to delete this slide data?';
        blnResponse = window.confirm(strMessage);
        if (blnResponse) {
            __doPostBack('DeleteSlide()', var_row  );
        }
    }
    catch (Err) {
        alert('DeleteSlide - ' + Err.description);
    }
}
但是当我点击删除链接按钮时,javascript不会启动

有什么问题吗

另外,我尝试使用CommandArgument和Container.DataItemIndex,但这导致了更多的错误,因此我最终使用了rowdatabound。

尝试以下方法:

DirectCast(e.Row.FindControl("LinkDelete"), LinkButton).OnClientClick = "javascript:DeleteSlide('" & Convert.ToString(e.Row.RowIndex) & "')";

浏览器控制台中有错误吗?没有。。。但我找到了解决办法。谢谢这就解决了问题。更改了.attributes.add to.onclientclick,它工作得非常好!谢谢!