Wednesday, March 21, 2012

Delete confirmation in GridView and Ajax

Hi, I'm performing an upgrade from a traditional asp.net 2.0 web site to asp.net ajax.

I could perform all the necessary upgrades in my application to work with ajax, but one: how can I ask the user (using a ok/cancel dialog) if he/she wants to delete some gridview row? (assuming I use a traditional "delete command column" in the grid)

1. I tried to set this up using triggers... but could not find a way to halt execution with a custom script an resume execution if users says "ok"

2. I tried to build a custom extender... but all I could do is "intercept clicks" on the gridview, not "when it happens in a delete command" (everywhere I click on the grid fires the popup)

if someone could point any resource I can look at or any clue...

thanks a lot,

Victor

here is the code

Protected Sub gv_Project_RowDataBound(ByVal senderAs Object,ByVal eAs GridViewRowEventArgs)Handles gv_Project.RowDataBoundIf e.Row.RowType = DataControlRowType.DataRowThen Dim lAs LinkButton =CType(e.Row.Cells(5).Controls(0), LinkButton)' 5 is your column count of delete column l.Attributes.Add("onclick","javascript:return " & "confirm('Are you sure you want to delete this record " & DataBinder.Eval(e.Row.DataItem, "Project_Name").ToString() & "')")End If End Sub
 
 
cheers 

thanks a lot!!!

this is really a much simpler task as I was wondering...

thanks again,

regards

Victor


Hello,

Thanks for this tip.

I have a GridView with both Deleting and Editing enabled.

My Code sets the e.Row.Cells index to 0 so that refers to the Gridview Command column.
Dim lAs LinkButton =CType(e.Row.Cells(1).Controls(0), LinkButton)

In this case the Confirmation if triggered on a click of Edit and not Delete.

I would appreciate and suggestion how to attach the confirmation to the "Delete" Link in the GridView Command Column.

Thanks Lex


Hello, I have solved this issue by creating 2 command buttons, one for the Edit and One for the Delete.

This then allowed the reference to the Link Button to index the Delete Cell or Column.

Thanks Lex


Thanks, working perfectly

No comments:

Post a Comment