Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi i have issues deleting a specific row in the gridview.
 
this is the error message:
 
Input string is not in a correct format
 
for this particular line
 
int shoppingCartID = Convert.ToInt32(delCart.CommandArgument);
 
any idea why?
 
in addition to this, the value for delCart.CommandArgument is userID and shoppingCartID :
 
int userID = Convert.ToInt32(Session["userID"] = "3");
int shoppingCartID = Convert.ToInt32(delCart.CommandArgument);
del.DeleteSCitems(userID, shoppingCartID);
Posted 15-Jun-13 8:11am
Edited 16-Jun-13 20:59pm
v2
Comments
Jerrell77 at 15-Jun-13 13:12pm
   
this gridview shows the shopping cart for my project
CHill60 at 15-Jun-13 13:14pm
   
What is the value of delCart.CommandArgument?
Jerrell77 at 15-Jun-13 14:09pm
   
will get back to you!
Jerrell77 at 17-Jun-13 2:00am
   
userID and shoppingCartID ?
Tadit Dash at 15-Jun-13 13:29pm
   
Debug and find what is the value of delCart.CommandArgument, which is creating problem I guess.
Jerrell77 at 15-Jun-13 14:08pm
   
ok will do and get back to you!
Tadit Dash at 15-Jun-13 15:01pm
   
Ok. Hit reply after you get it.
Jerrell77 at 17-Jun-13 1:46am
   
hi the error message shows "Input string was not in a correct format" and "Server error in / Application". any idea why?
Tadit Dash at 17-Jun-13 3:34am
   
Can you show the markup of gridview in aspx page?
Jerrell77 at 17-Jun-13 3:38am
   
nope cant show it out
Tadit Dash at 17-Jun-13 4:32am
   
Why? Is there any problem? Then tell me what have you specified in CommandArgument of that control?
Jerrell77 at 17-Jun-13 4:41am
   
int userID = Convert.ToInt32(Session["userID"] = "3");
int shoppingCartID = Convert.ToInt32(delCart.CommandArgument);
del.DeleteSCitems(userID, shoppingCartID);
 
these are the statements
Tadit Dash at 17-Jun-13 4:50am
   
No, I am not asking that.
In that markup of control in aspx page, what have you specified in CommandArgument atrribute?
Jerrell77 at 17-Jun-13 2:00am
   
the value is shoppingCartID and UserID?

1 solution

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

Solution 1

Hi
 
Follow the below one, If you are using GridView_RowCommand:
 
GridViewRow gRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int RowIndex = gRow .RowIndex; 
 
Use the row index and get the selected row id and delete the record.
 
Click on Delete boutton and it is inside item template:
GridViewRow gRow = (GridViewRow)((ImageButton)(sender)).NamingContainer;
string strId = ((HiddenField)gRow.FindControl("hdnId")).Value;
 
use the strId and delete.
 
Regards
Wills
  Permalink  
Comments
Jerrell77 at 17-Jun-13 1:45am
   
@willington.d what is the "hdnId" suppose to be?

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



Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 17 Jun 2013
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