我想触发一个 javascript 来确认删除该行。
这是行数据绑定
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 不会触发。
有什么问题?
PS 我尝试使用 CommandArgument 和 Container.DataItemIndex 但这会导致更多错误,所以我最终使用了 rowdatabound。