Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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.
 
regards
manohar
Posted 10-Sep-12 1:53am
Edited 10-Sep-12 1:55am
_Amy51.3K
v2
Comments
Karthik Harve at 10-Sep-12 6:55am
   
can you elaborate your question ? if possible paste your code.
Mohamed Mitwalli at 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 at 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");
 
viewdetails(int.Parse(lblslno.Text));
 
}
 
private void viewdetails(int sl)
{
con.Open();
SqlCommand cmd = con.CreateCommand;
cmd.CommandText = "Home_userrecordhit_spinsert";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@mtid", sl);
cmd.Parameters.AddWithValue("@useremailid", usrid);
 
cmd.ExecuteNonQuery();
 
con.Close();
}
 
this is my code
Manohar_manu at 10-Sep-12 10:36am
   
and sp
 
ALTER proc Home_userrecordhit_spinsert
@mtid int,
@useremailid varchar(50)
as
 

 
insert into Home_userrecordhit (mtid,useremailid,recorddate)values(@mtid,@useremailid,getdate())
Rickin Kane at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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,
—SA
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100