Tuesday, December 9, 2008

Delete Command Twice in GridView

The delete command is being called twice for each click on delete. What do I mean by this? With this code:

<asp:GridView runat="server" DeleteMethod="DeleteRowById" ...>
    <asp:CommandField ShowDeleteButton="True" />

I am getting the DeleteRowById method called which when the delete button in the CommandField is clicked. Doing some Internet research I found this:


However, the workaround isn't right, basically all you need to do is change the <asp:CommandField to:

     <asp:ImageButton runat=server id="ImageButton1" CommandName="Delete" ImageUrl="..."
    CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' />

You don't need to add a code behind event handler for the ImageButton Command event.


No comments:

Post a Comment