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 13 Exercise 3 solution (http://p2p.wrox.com/showthread.php?t=67531)

firblazer April 18th, 2008 09:55 PM

Chapter 13 Exercise 3 solution
 
Hi Imar,

On page 678, exercise 3 solution, you wrote:

Code:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl= '<%# "PictureDetails.aspx?Id=" + Eval("Id") %>'>
I ran it but it says "no data returned" for all the albums.
When I changed the "+" sign to "&" sign of the code, it works. BTW, I am using VB coding. Could it be your code is for C#?

Thanks.


planoie April 18th, 2008 10:59 PM

Yes, you are correct. In the example solution the markup is in C#.

My apologies, I should have caught that during technical review.

-Peter
peterlanoie.blog

firblazer April 19th, 2008 02:45 AM

Hi Peter,

That's strange. I tried out another "Try It Out" on page 507 today and I used "+" instead of "&" and it works fine.

What is stranger is the message it returns. What did it give a "no data returned" in the web browser when it should have given me an error in VWD?

Thanks.


Imar April 19th, 2008 07:16 AM

Hi there,

You probably don't get "No data returned", but due to an error the page is not updated and still shows the old "no data" message. Just for fun, try this:

1. Restore the + again in the code

2. Remove the <UpdatePanel> and <ContentTemplate> or turn on JavaScript debugging through Tools | Internet Options | Advanced in IE.

3. Rerun the page. Now you get an error like this:

Line: 5
Error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: Conversion from string "PictureDetails.aspx?Id=" to type 'Double' is not valid.

Alternatively you may get:

[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conve rsions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +211
Microsoft.VisualBasic.CompilerServices.Conve rsions.ToDouble(String Value, NumberFormatInfo NumberFormat) +74

So, the conversion failed right away. Due to the Ajax UpdatePanel, you probably never got the error in the browser.

The Tio in Chapter 14, page 507 works because the Id is converted to a String:

NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Eval("Id").ToString() %>'

In this example, both ends of the assignment operations are strings, so concatenation works as expected. In the problem you posted, the code tries to "add up" the string and the Id which obviously fails.

There are two ways to fix it:

1. Use &. This tells the VB compiler to concatenate the values rather than try to add them to each other.

2. Use ToString() on Eval("Id"). This removes the ambiguity between the two sides of the assignment, so again the compiler knows it should concatenate, rather than add the two values to each other.

Thanks for catching and reporting this; I'll file an errata for it.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 12:42 PM.

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