Gridview RowCommand Issue

I have a gridview in an 4.0 website.

I have a link button in the gridview that sends a command name to the code behind RowCommand event.  The link button also has an OnClientClick event that does a confirmation.

The issue is that after the confirmation box is confirmed, the row command cannot find the index from the command arguments.  The command name is sent successfully but not he arguments.

The error states, "Input string was not in a correct format."
Please help.
'gridview linkbutton code
     <asp:LinkButton ID="LinkButton2" Runat="server"   OnClientClick="return confirm('Are you sure you want to delete this fish?');" CommandName="ConvertRow">Convert</asp:LinkButton>

'codebehind code that fires the error
Dim index As Integer = Convert.ToInt32(e.CommandArgument)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alfred A.Commented:
this problem occurs when you try to convert non numeric or empty string into integer
Alfred A.Commented:
Additional suggestion, try to use Int32.TryParse or use IsNumeric function to check if value is numeric or not.
dtechfishAuthor Commented:
It doesn't seem that the index is even getting sent to the codebehind function from the client confirm script.  When I debug and look at the value of the command arg. it is empty or "".  When I do not use the onlclientclick script the correct index is sent and the code works.

Any Ideas?
Alfred A.Commented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dtechfishAuthor Commented:
I solved this issue by setting the Command Argument manually using CommandArgument="<%# Container.DataItemIndex %>".  Duh....Not sure why I couldn't figure that one out.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.