Friday, November 28, 2008

How to... use an Ajax ConfirmExtender in a GridView

A typical case to use an ajax-confirmbutton within a gridview is to delete a row on DB, let's take a look...

So, in our gridview, we have to create an "ItemTemplate", then add a LinkButton and the ajax ConfirmButtonExtender.
Set the property of our Extender like "TargetContolId" (= the LinkButton ID) and the "Confirm Text" (= Are You sure, continue?).
In this way we have connected the extender with the LinkButton !
Now we must connect the LinkButton with the data from the source (DataTable-method or a Control DataSource) in particular with an unic "row-ID"
Then go to Click-Event of the LinkButton to add the code to delete the row on DB...
something like:

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'delete after Ajax-ConfirmButtonExtender
Dim lb As LinkButton = sender
Dim objDel As New clSessionTest(("ConnectionString"))
objDel = Nothing
End Sub


2012 | aspnet code by Michele | don't try this at home
Mirko Iodice Notageek
Vladimir Carrer Carrer web log