Click here to Skip to main content
12,402,189 members (71,646 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# VS2010 Gridview
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 7:11am
Updated 16-Jun-13 19:59pm
v2
Comments
Jerrell77 15-Jun-13 13:12pm
   
this gridview shows the shopping cart for my project
CHill60 15-Jun-13 13:14pm
   
What is the value of delCart.CommandArgument?
Jerrell77 15-Jun-13 14:09pm
   
will get back to you!
Jerrell77 17-Jun-13 2:00am
   
userID and shoppingCartID ?
Tadit Dash 15-Jun-13 13:29pm
   
Debug and find what is the value of delCart.CommandArgument, which is creating problem I guess.
Jerrell77 15-Jun-13 14:08pm
   
ok will do and get back to you!
Tadit Dash 15-Jun-13 15:01pm
   
Ok. Hit reply after you get it.
Jerrell77 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 17-Jun-13 3:34am
   
Can you show the markup of gridview in aspx page?
Jerrell77 17-Jun-13 3:38am
   
nope cant show it out
Tadit Dash 17-Jun-13 4:32am
   
Why? Is there any problem? Then tell me what have you specified in CommandArgument of that control?
Jerrell77 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 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 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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 17 Jun 2013
Copyright © CodeProject, 1999-2016
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