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" />
</asp:GridView>

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

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105123

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

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

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

{6230289B-5BEE-409e-932A-2F01FA407A92}

Comments

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape