How to ask for confirmation when using the delete command in gridview? By default it just deletes the item right away.
Answer: Disable the "Show Delete" Option and Put below code in the grid template.
"
<asp:TemplateField><ItemTemplate>
<asp:LinkButton ID="lnkDeleteBtn" Runat="server" OnClientClick="return ConfirmDelete();"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
"
Also put this piece of javascript in the header section.
"<script type="text/javascript">
function ConfirmDelete() {
return confirm("Are you sure to delete?");
}
</script>"
No comments:
Post a Comment