在gridview rowdatabound中设置onclientclick后未触发javascript
我想启动一个javascript来确认删除该行 这是rowdatabound在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
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,它工作得非常好!谢谢!