Click here to Skip to main content
14,698,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 sub GridView1_RowCommand(ByVal Sender as Object,ByVal e as GridViewCommandEventArgs)
dim index as integer=Convert.Toint32(e.CommandArgument)
dim id=GridView1.Rows(index).cells(0).Text
if e.CommandName="Delete"
Delete() 'This the function to delete rows from DB table
end if</pre>


When the Image Button with the
commandName "Delete"
is clicked the function
"GridView1_RowCommand(ByVal Sender as Object,ByVal e as GridViewCommandEventArgs)"
gets invoked...
But after deleting the row the control again comes back to the same function and as the row is deleted in the first calling itself ,it shows error...?
How to avoid calling twice the same function?
Posted

Sounds like a known issue!
Look here: GridView RowCommand Event Firing Twice [^]

There is a simple solution to it. Convert the buttoncolumn to a templatecolumn. Then add an imagebutton:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Delete" CommandArgument='<%# Eval("SomeValue") %>'

ImageUrl="~/Images/extras/addtocart.gif" />
</ItemTemplate>
</asp:TemplateField>

After this Row command would fire only once.
   
v2
Comments
Ankur\m/ 28-Aug-10 6:44am
   
Oh! :doh:
Viral Upadhyay 28-Aug-10 8:01am
   
Nice share Sandeep.
I guess there is something in your delete function which is causing it.
What's the CommandSource value when the event is raised 2nd time?
   
Comments
Sandeep Mewara 28-Aug-10 6:36am
   
It's a known issue. Look at my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900