• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 985
  • Last Modified:

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

0
dtechfish
Asked:
dtechfish
  • 3
  • 2
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now