Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2008, 12:40 PM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default Input string was not in a correct format.

Hi,

I want to delete the selected row in the gridview when clicking on the linkbutton. There is no delete command in the aspx file (because data is fetched from several tables), so i try to do that with the rowcommand in code-behind like this:

aspx file:
---------
<asp:GridView ID="GridView1" DataKeyNames="gridkey" ...>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" runat="server"
OnClientClick="return confirm('sure?');"
CommandName="Delete" Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
...
</asp:GridView>

code-behind:
-----------
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
Dim r As Int32
Dim dbkey As String
r = Convert.ToInt32(e.CommandArgument)
dbkey = Convert.ToInt32(GridView1.DataKeys(r).Value)
End Sub

I have two questions:
1) i get the error: "Input string was not in a correct format. "
2) do i need somewhere a delete command (sql="delete from ...") . Do i have to define the connectionstring, open the connection etc ..?

Thanks
H.

 
Old February 17th, 2008, 02:59 PM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Set break-point in the beginning of GridView1_RowCommand method. Does it get called at all? Go step-by-step through that method and see if that Convert.ToInt32(...) is throwing the error. You could try something like the following in order to isolate the problem:

Code:
Protected Sub GridView1_RowCommand(...)
    Dim r As Int32
    Dim dbkey As String

    If Not Int32.TryParse(e.CommandArgument, r) Then
        Throw New Exception("CommandArgument was not of integer type")
    End If

    If Not Int32.TryParse(GridView1.DataKeys(r).Value, dbkey) Then
        Throw New Exception("GridView1.DataKeys(r).Value was not of integer type")
    End If

End Sub
 
Old February 19th, 2008, 06:22 PM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 8 April 29th, 2010 05:56 AM
Input string was not in a correct format. Silfverduk VB.NET 2002/2003 Basics 1 May 20th, 2006 04:58 AM
input string was not in a correct format kunal.net VS.NET 2002/2003 1 October 11th, 2005 12:18 AM
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 2 April 4th, 2005 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.