Add a JavaScript Confirm function when deleting a row from a datagrid
Lets say your datagrid looks like this:
<asp:datagrid OnItemDataBound="dg1_OnItemDataBound"...>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button runat="server" Text="Delete" id="btnDelete" CommandName="Delete" CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
...
</asp:datagrid>
And in your ItemDataBound of the datagrid you just need to add this:
Sub dg1_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
CType(e.Item.Cells(0).FindControl("btnDelete"), Button).Attributes.Add("onClick", "return confirm('Are you sure to delete this item?')")
End If
End Sub
Sonu