<%@ Page %>
Confirming Deletes in DataGrid
The web form
The Delete button
<asp:DataGrid id="DataGrid1" runat="server">
Private Sub DataGrid1_ItemDataBound
(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Dim l As LinkButton
If e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem Then
l = CType(e.Item.Cells(0).FindControl("cmdDel"), LinkButton)
l.Attributes.Add("onclick", "return getconfirm();")
Here we check whether the item (row) is of type Item or AlternatingItem. We then add DHTML OnClick event handler that calls a client side function getconfirm().
The getconfirm function looks like this:
if (confirm("Do you want to delete record?")==true)
I hope it was interesting. See you soon.