Welcome Guest Search | Active Topics | Sign In | Register

Dialog as confirm delete in gridview Options
Paul Creedy
Posted: Wednesday, June 27, 2007 7:16:26 AM
Rank: Advanced Member
Groups: Member

Joined: 6/5/2007
Posts: 76
I have a gridview with a custom button (in a template) that calls a method that deletes the currently selected row.

Note, I'm not using the built in delete command, but a custom button.

Is there a way to use the dialog as a pop up confirm delete yes/no?

If so what do I put on the button and how do I capture if it was yes/no?

<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" CommandName="Delete" CommandArgument='<%# Eval("UserName") %>'
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

Code behind:
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

Select Case e.CommandName

Case = "Delete"
'
'
'
'

End Select
End Sub
eo_support
Posted: Wednesday, June 27, 2007 7:39:44 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi Paul,

I do not see an easy way to that. At the minimum you will need to do some tweaking with the build in buttons. The way the button works is:

1. User clicks the button;
2. It triggers onclick event handler (generated by ASP.NET), which calls _doPostBack;

You will need to change it to work in the following way:
1. First you need to either save the original onclick event handler or figure out how it is generated so that you can “simulate” such an action later;
2. You will then replace it with your own click handler. Your own click handler will display the dialog and return false;
3. When user clicks OK on the dialog, your code then calls the original onclick hanlder. If the user clicks CANCEL, then you do nothing;

The original onclick handler is usually a _doPostBack call (you can find out by viewing page source) but it can get rather complicated if you have validators on your page. If you also use an AJAX solution, that will further complicate the situation. As such I would recommend you to balance the complexity and the benefit before going into it. :)

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.