Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 March 25th, 2012, 04:08 PM
Authorized User
 
Join Date: Dec 2011
Posts: 26
Thanks: 1
Thanked 4 Times in 3 Posts
Default ch. 14 exercise 3 question on hyperlink syntax

i have just started trying to do ch. 14 exercise 3. i thought of doing the hyperlink on the image but trouble getting it working. i took a look at just the beginning of your answer. i noticed your data binding snytax starts right after the NavigateUrl= (like NavigateUrl="<%# PhotoDetails.aspx?Id=..."). i expected the syntax to be more like
NavigateUrl="PhotoDetails.aspx?Id= <%# Eval('Id') %>"
or maybe
NavigateUrl="'PhotoDetails.aspx?Id=' + <%# Eval("Id") %>"

why do you begin the "<%#" right after the navigateUrl? Doesn't the compiler get confused by stuff other than the eval or bind statements being in there? Also, is there a way to construct the syntax as i was expecting that would work?
 
Old March 26th, 2012, 02:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The literal string "PhotoDetails.aspx?Id= is also part of the binding expression. Everything between <%# and %> is part of the binding expression and executed when the control is bound. In other words,

'<%# "PhotoDetails.aspx?Id=" + Eval('Id') %>'

means: execute the code between <%# and %>. That in turn means that this code gets executed:

"PhotoDetails.aspx?Id=" + Eval('Id')

This is how you would normally build up a string in Code Behind as well; Eval is just a method that returns the value of the request property. So, given an ID of 10 for the current item, this would result in:

"PhotoDetails.aspx?Id=" + "10"

which results in

PhotoDetails.aspx?Id=10

which is then assigned to the NavigateUrl.

Does this help?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 Exercise 3 Solution pg 747 arodrigu12 BOOK: Beginning ASP.NET 4 : in C# and VB 2 April 21st, 2011 07:58 PM
Chapter 14 Exercise 3 and solution. UncleJeff BOOK: Beginning ASP.NET 4 : in C# and VB 2 March 14th, 2011 02:15 PM
Chap. 14 Exercise 2 C#Book stoverje BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 July 1st, 2008 09:41 AM
Hyperlink syntax? shmacgregor ASP.NET 1.0 and 1.1 Basics 2 February 19th, 2004 09:36 PM
C#: Chapter 14 - Exercise 3 Tchami BOOK: Beginning ASP.NET 1.0 0 November 26th, 2003 02:48 PM





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