p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   Chapter 12 (page 400) Try It Out: Applying Filter (http://p2p.wrox.com/showthread.php?t=69305)

Deepeshk July 10th, 2008 11:32 PM

Chapter 12 (page 400) Try It Out: Applying Filter

I tried this code, and it shows up an error

Please help, i am completely new to asp.net

Later when i deleted the row <asp:ListItem>"Please make your choice"</asp:ListItem> it ran perfectly, was this the cause of error?


<%@ Page Language="VB" MasterPageFile="~/MasterPages/ManagementMaster.master" AutoEventWireup="false" CodeFile="Reviews.aspx.vb" Inherits="Reviews" title="Planet Wrox - Management Reviews" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
        AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name"
                <asp:ListItem>"Please make your choice"</asp:ListItem>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="Id" DataSourceID="SqlDataSource2"
                style="font-family: Arial, Helvetica, sans-serif; font-size: small">
                    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
                        ReadOnly="True" SortExpression="Id" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Summary" HeaderText="Summary"
                        SortExpression="Summary" />
                    <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
                    <asp:BoundField DataField="GenreId" HeaderText="GenreId"
                        SortExpression="GenreId" />
                    <asp:CheckBoxField DataField="Authorized" HeaderText="Authorized"
                        SortExpression="Authorized" />
                    <asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime"
                        SortExpression="CreateDateTime" />
                    <asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime"
                        SortExpression="UpdateDateTime" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
                SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
            <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
                SelectCommand="SELECT * FROM [Review] WHERE ([GenreId] = @GenreId)">
                    <asp:ControlParameter ControlID="DropDownList1" Name="GenreId"
                        PropertyName="SelectedValue" Type="Int32" />
Error Message below
Server Error in '/WebSite1' Application.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2755599
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +112
   System.String.System.IConvertible.ToInt32(IFormatP rovider provider) +43
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +293
   System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +264
   System.Web.UI.WebControls.Parameter.get_ParameterV alue() +66
   System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext context, Control control) +254
   System.Web.UI.WebControls.SqlDataSourceView.Initia lizeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +274
   System.Web.UI.WebControls.SqlDataSourceView.Execut eSelect(DataSourceSelectArguments arguments) +754
   System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.Perform Select() +149
   System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

Imar July 12th, 2008 04:18 AM

Hi Deepesh,

Take a look at step 9 on page 402:

quote:Save all your changes and open Reviews.aspx in your browser. If you get an error, ensure that you set the Value of the static ListItem in the drop-down list to an empty string (“”).
Step 10 on page 400 shows this as well. Looks like you forgot that step as your ListItem looks like this:

<asp:ListItem>"Please make your choice"</asp:ListItem>
instead of this:

<asp:ListItem Value="">Please make your choice</asp:ListItem>
Without the empty value attribute, the text Please make your choice is used as the drop down's value. This text cannot be converted to an Integer to be passed SelectParameters for the DataSource and thus you get the error you posted.

Hope this helps,


Imar Spaanjaars
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

All times are GMT -4. The time now is 02:14 PM.

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