Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 July 9th, 2010, 03:14 PM
Registered User
Join Date: Mar 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chpt 13 Updating a review

Hi All.
All was going well with the chapter until I tried to update a review. I can insert a review just fine but when I try to update a review I get an exception error. "systemFormatException: input string was not in correct format. I noticed that when I place the mouse courser over the review I see an id0 instead of the action ID number of the review. I am not sure what code you need to see to help, so I am inserting the reviews.aspx page.
<%@ Page Title="Planet Wrox - Management - Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Reviews.aspx.cs" Inherits="Management_Reviews" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
        AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name" 
        <asp:ListItem Value="">Make a selection</asp:ListItem>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="Id" DataSourceID="SqlDataSource2">
            <asp:HyperLinkField DataNavigateUrlFields="Id" 
                DataNavigateUrlFormatString="AddEditReview.aspx?Id=(0)" DataTextField="Title" 
                HeaderText="Title" />
            <asp:TemplateField HeaderText="Authorized" SortExpression="Authorized">
                    <asp:Label ID="AuthorizedLabel" runat="server" Text='<%# GetBooleanText(Eval("Authorized")) %>' />
            <asp:BoundField DataField="CreateDateTime" DataFormatString="{0:g}" 
                HeaderText="CreateDateTime" HtmlEncodeFormatString="True" SortExpression="CreateDateTime" />
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
    <a href="AddEditReview.aspx">Insert New Review</a><asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
        DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id" 
        InsertCommand="INSERT INTO [Review] ([Title], [Authorized], [CreateDateTime]) VALUES (@Title, @Authorized, @CreateDateTime)" 
        SelectCommand="SELECT [Id], [Title], [Authorized], [CreateDateTime] FROM [Review] WHERE ([GenreId] = @GenreId)" 
        UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Authorized] = @Authorized, [CreateDateTime] = @CreateDateTime WHERE [Id] = @Id">
            <asp:Parameter Name="Id" Type="Int32" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:ControlParameter ControlID="DropDownList1" Name="GenreId" 
                PropertyName="SelectedValue" Type="Int32" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:Parameter Name="Id" Type="Int32" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
        SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
My gut feeling is that I am not passing the correct ID number. Any help would be appreciated.

Old July 9th, 2010, 03:24 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Your reasoning is correct and you're indeed not passing the corrrect ID. To find and fix issues like this, take a look at the address of the update page in the browser. I think instead of seeing something lke AddEditReview.aspx?Id=123 you see AddEditReview.aspx?Id=(0), right?

That's because of this:

<asp:HyperLinkField DataNavigateUrlFields="Id" 
      DataNavigateUrlFormatString="AddEditReview.aspx?Id=(0)" DataTextField="Title" 
      HeaderText="Title" />
You're using parentheses (0) instead of curly braces {0} which is required to correctly pass the ID to the next page.

Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
wildcatfan101 (July 9th, 2010)
Old July 9th, 2010, 11:14 PM
Registered User
Join Date: Mar 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts

That was it. Thank you for your help.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Review pCarsten BOOK: Expert PHP and MySQL 0 April 2nd, 2010 11:00 AM
Chpt 9 Reporting ZeroFactorial BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 1 October 9th, 2009 02:50 PM
Chpt 13 - issue with DNN controls not appearing in VS2008 Meister1867 BOOK: Professional DotNetNuke 5: Open Source Web Application for ASP.NET ISBN: 978-0-470-43870-1 0 August 29th, 2009 09:31 PM
Wrox United ECommerce Chpt 13 KDSTECH BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 December 19th, 2008 12:13 PM
Chpt 3 Please Help Me! nmj001 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 July 24th, 2003 10:52 PM

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