Sunday, October 24, 2010

Gridview RowEditing or RowDeleting event fires twice problem

Problem:
When working with ASP.Net Gridview control's RowEditing or RowDeleting events, it fires twice if image is used in Edit or Delete CommandField. Many ASP.Net developers face this problem while working with Gridview controls. There is many post in different forum on this problem.

Solution:
To solve this problem convert CommandField to TemplateField and add an ImageButton to show your Edit or Delete image.

Example Code:


<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/Image/admin/edit.gif" Text="Edit" />
ItemTemplate>
asp:TemplateField>

Thanks.

1 comment:

  1. Hi friend,

    Your post is useful...

    ReplyDelete