Question

I want to fire a javascript to confirm deleting the row.

This is the 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

This is the 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);
    }
}

but when I click the delete link button, the javascript won't fire.

What's the problem?

P.S. I tried using the CommandArgument and Container.DataItemIndex but that caused a whole lot more errors so I ended up using the rowdatabound.

Was it helpful?

Solution

Try this:

DirectCast(e.Row.FindControl("LinkDelete"), LinkButton).OnClientClick = "javascript:DeleteSlide('" & Convert.ToString(e.Row.RowIndex) & "')";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top