ASP.NET GridView RowDeleting event fires twice!

This is a well known bug (for Microsoft) when using ImageButton. Of course you can use standard button or link button to go round the problem.

Here is a solution with image button:

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

protected void ImageButton1_Command(object sender, CommandEventArgs e) {
GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString() ));
}

No comments:

Post a Comment