Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Input string was not in a correct format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bart - 13 Feb 2008 20:51 GMT
Hi,

i defined a linkbutton in a gridview. In code-behind, i want to perform the
delete query when the user clicks on the linkbutton, but this code gives
following error:
"Input string was not in a correct format." at line:  r =
Convert.ToInt16(e.CommandArgument)

Thanks for help
Bart

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

code-behind:
-------------
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand
       Dim r As Int16
       Select Case e.CommandName
           Case "Delete"
               r = Convert.ToInt16(e.CommandArgument)
               Me.GridView1.DeleteRow(r)
       End Select
End Sub
gnewsgroup - 13 Feb 2008 20:57 GMT
> Hi,
>
[quoted text clipped - 33 lines]
>         End Select
> End Sub

Because you did not assign any values to CommandArgument, and by
default it's String.Empty, which cannot be converted to an Int16.
Bart - 13 Feb 2008 21:24 GMT
Thanks for replying, but

I have no idea which value to assign  to CommandArgument. I guess it needs
the index of the selected row ...

On Feb 13, 3:51 pm, "Bart" <b...@b.d> wrote:
> Hi,
>
[quoted text clipped - 34 lines]
> End Select
> End Sub

Because you did not assign any values to CommandArgument, and by
default it's String.Empty, which cannot be converted to an Int16.
gnewsgroup - 13 Feb 2008 22:12 GMT
> Thanks for replying, but
>
[quoted text clipped - 46 lines]
>
> - Show quoted text -

So, you would like to have the row index?  Can you do the following?

<asp:TemplateField>
 <ItemTemplate>
   <asp:Button ID="AddButton" runat="server"
     CommandName="AddToCart"
     CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
     Text="Add to Cart" />
 </ItemTemplate>
</asp:TemplateField>

It should work for a LinkButton, too.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.