Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
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 ?
Debug and find what is the value of delCart.CommandArgument, which is creating problem I guess.

1 solution

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:
C#
GridViewRow gRow = (GridViewRow)((ImageButton)(sender)).NamingContainer;
string strId = ((HiddenField)gRow.FindControl("hdnId")).Value;


use the strId and delete.

Regards
Wills
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900