ASP.net Gridview RowCommand Issue

I have a gridview in an asp.net 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:TemplateField>
   <ItemTemplate>
     <asp:LinkButton ID="LinkButton2" Runat="server"   OnClientClick="return confirm('Are you sure you want to delete this fish?');" CommandName="ConvertRow">Convert</asp:LinkButton>
   </ItemTemplate>
</asp:TemplateField>

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

Open in new window

dtechfishAsked:
Who is Participating?

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

x
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

http://forums.asp.net/t/956277.aspx
0
Alfred A.Commented:
Additional suggestion, try to use Int32.TryParse or use IsNumeric function to check if value is numeric or not.
0
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?
0
Alfred A.Commented:
0

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.
0
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.