Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void gvCartView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Remove")
        {
            int ProductId = Convert.ToInt32(e.CommandArgument);
            ShoppingCart.Instance.RemoveItem(ProductId);
        }
   }


I have tried everything. Can someone help me out.
Posted
Updated 20-Jun-14 2:36am
v2
Comments
ZurdoDev 20-Jun-14 8:30am    
The error means that e.CommandArgument is not an Integer. All you have to do is debug it.
Thanks7872 20-Jun-14 8:37am    
Should be posted as solution. Go for it.
Bernhard Hiller 20-Jun-14 8:48am    
e.CommandName = "Remove";
e.CommandArgument = "Bacon";
=> input string was not in correct format
PIEBALDconsult 20-Jun-14 9:02am    
And never use Convert.
Sergey Alexandrovich Kryukov 20-Jun-14 14:09pm    
There are more rare cases when Convert really should be used. But when Parse/TryParse can do the job, I advice to prefer it.
—SA

The error said that the string you are trying to parse an integer from does not actually contain a valid integer.
You should use Int32.TryParse[^] method.
 
Share this answer
 
You need to set CommandArgument to RowIndex as below, if you want to use it in the RowCommand event of your GridView.
HTML
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />


Have a look at below link for more details on this.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.110).aspx
 
Share this answer
 
sir, you can use try parse with "e.CommandArgument" it will help you get the right result.
 
Share this answer
 

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