Click here to Skip to main content
14,971,553 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Ih've an issue regarding gridview button click. when i click button inside a gridview data is saving in a database twice.can anyone help regarding this issue.

Updated 10-Sep-12 0:55am
Karthik Harve 10-Sep-12 6:55am
can you elaborate your question ? if possible paste your code.
Mohamed Mitwalli 10-Sep-12 7:04am
It's not clear Try to debug your code and see what's happen otherwise share your code .
Manohar_manu 10-Sep-12 10:34am
if (e.CommandName == "vmore") {
int index = int.Parse(e.CommandArgument.ToString());
GridViewRow gr = GridView1.Rows(index);
//Dim btn1 As MultiView = DirectCast(gr.FindControl("MultiView1"), MultiView)
ImageButton imgbtnsvm = (ImageButton)gr.FindControl("vmore");

Label lblslno = (Label)gr.FindControl("lblslno");



private void viewdetails(int sl)
SqlCommand cmd = con.CreateCommand;
cmd.CommandText = "Home_userrecordhit_spinsert";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@mtid", sl);
cmd.Parameters.AddWithValue("@useremailid", usrid);



this is my code
Manohar_manu 10-Sep-12 10:36am
and sp

ALTER proc Home_userrecordhit_spinsert
@mtid int,
@useremailid varchar(50)

insert into Home_userrecordhit (mtid,useremailid,recorddate)values(@mtid,@useremailid,getdate())
Rickin Kane 10-Sep-12 21:47pm
i am still not sure what exactly are you trying to do here , first of all you are raising the event Row Command for grid and find control Label , if row command is pressed , that means Data is already in Database , and you need to only update it , since you find the Label lblslno and passing it to SP for inserting again ,

Still not sure , if i am correct but check if you need to insert or Update the record

1 solution

This problem is one of the simplest for debugging. You have some code which is called twice when it's expected to be called once. This is already good, much easier than the case when some code is not called at all. Here is what you need to do:

Run your application under debugger and set a break point on the line of code which is called twice instead of one. When execution is stopped, open a Debug window called "Call Stack". This window will show you all the stack from the very top, so you can see through what calls your code was called for the first time, with file and lines of code for each stack frame. When you got the idea, resume the execution to stop in on this break point again. Repeat it to see all calls. If you missed something and cannot come to the same code fragment with the same stack state, restart the application and repeat it all. This way, you can pinpoint the problem really quickly.

A note for future: you really need to use the debugger if you have a slightest concern of your run-time behavior. You also need to do it before asking similar questions at this forum. Doing some homework before asking questions can pay off really well.

Good luck,

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