Click here to Skip to main content
11,927,324 members (52,808 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#2.0 C#
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.

Posted 10-Sep-12 1:53am
Edited 10-Sep-12 1: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

Rate this: bad
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,

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2015
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