<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Things I've learnt from developing an ASP.NET application</title>
	<atom:link href="http://learningthehardway.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://learningthehardway.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 26 Mar 2008 11:22:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='learningthehardway.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Things I've learnt from developing an ASP.NET application</title>
		<link>http://learningthehardway.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://learningthehardway.wordpress.com/osd.xml" title="Things I&#039;ve learnt from developing an ASP.NET application" />
	<atom:link rel='hub' href='http://learningthehardway.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Hyperlink controls and data binding</title>
		<link>http://learningthehardway.wordpress.com/2008/03/26/hyperlink-controls-and-data-binding/</link>
		<comments>http://learningthehardway.wordpress.com/2008/03/26/hyperlink-controls-and-data-binding/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 11:22:20 +0000</pubDate>
		<dc:creator>Simon Fletcher</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[LISTVIEW]]></category>
		<category><![CDATA[Eval]]></category>
		<category><![CDATA[HyperLink]]></category>

		<guid isPermaLink="false">http://learningthehardway.wordpress.com/?p=13</guid>
		<description><![CDATA[An application I&#8217;m working on at the moment needs to display a list of products and provide a link against each product to another page where the product details can be edited. I want the link to pass the ID of the product to be edited as a parameter. I had some difficulty figuring out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learningthehardway.wordpress.com&amp;blog=3269077&amp;post=13&amp;subd=learningthehardway&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An application I&#8217;m working on at the moment needs to display a list of products and provide a link against each product to another page where the product details can be edited.  I want the link to pass the ID of the product to be edited as a parameter.  </p>
<p>I had some difficulty figuring out how to create a HyperLink control with a NavigateURL property that contained the ID so, once I figured it out, I thought I&#8217;d write a post for anyone else having difficulty with what must be a fairly common scenario.</p>
<p>At it&#8217;s simplest, data binding uses the Eval expression placed between delimiters and looks something like this:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/simpleeval.jpg' title='Simple Eval'><img src='http://learningthehardway.files.wordpress.com/2008/03/simpleeval.jpg?w=700' alt='Simple Eval' /></a></p>
<p>I used the Northwind database and created a SQLDataSource and a ListView control which I used to embed a table with 2 columns for the Product ID and the Product Name and use the Eval expression to poulate the columns of each row.  The code looked like this:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/initialcode.png' title='Initial Code'><img src='http://learningthehardway.files.wordpress.com/2008/03/initialcode.png?w=700' alt='Initial Code' /></a></p>
<p>and produced this result:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/initialcoderesult.png' title='Results of Initial Code'><img src='http://learningthehardway.files.wordpress.com/2008/03/initialcoderesult.png?w=700' alt='Results of Initial Code' /></a></p>
<p>I wanted to be able to click on the product name to open the page for editing the product details, so I need to replace the product name text</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/evalproductname1.png' title='Eval Product Name'><img src='http://learningthehardway.files.wordpress.com/2008/03/evalproductname1.png?w=700' alt='Eval Product Name' /></a></p>
<p>with a HyperLink which displayed the product name but linked to a different page and passed the Product ID as a parameter.</p>
<p>First the easy bit.  After adding a HyperLink control I took the Eval expression used previously and set the text property equal to it, placing it in single quotes.</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/textproperty.png' title='Text Property'><img src='http://learningthehardway.files.wordpress.com/2008/03/textproperty.png?w=700' alt='Text Property' /></a></p>
<p>The more difficult bit was setting the NavigateURL property, which needs to contain the link and the relevant product ID.  The format would be NavigateURL=?= resulting in a link such as &#8220;Default.aspx?ProductID=22&#8243;.</p>
<p>My initial thought was to try to concatenate the &#8220;?=&#8221; part, which would be constant, with the data binding expression, like this:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/wrong1.png' title='First try doesn’t work'><img src='http://learningthehardway.files.wordpress.com/2008/03/wrong1.png?w=700' alt='First try doesn’t work' /></a></p>
<p>However this resulted in the error &#8220;If this attribute value is enclosed in quotation marks, the quotation marks must match.&#8221;.  </p>
<p>I tried replacing &#8220;&amp;&#8221; with &#8220;+&#8221; but got the same error message.</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/wrong2.png' title='Doesn’t work either'><img src='http://learningthehardway.files.wordpress.com/2008/03/wrong2.png?w=700' alt='Doesn’t work either' /></a></p>
<p>After some trial and error I came up with this:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/right.png' title='This works'><img src='http://learningthehardway.files.wordpress.com/2008/03/right.png?w=700' alt='This works' /></a></p>
<p>The key difference is that rather than just placing the data binding expression between the delimiters, the whole thing needs to be within the delimiters.  The final code looked like this:</p>
<p><a href='http://learningthehardway.files.wordpress.com/2008/03/finalcode.png' title='The Final Code'><img src='http://learningthehardway.files.wordpress.com/2008/03/finalcode.png?w=700' alt='The Final Code' /></a></p>
<p>That&#8217;s it.  Hope this is useful to someone!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/learningthehardway.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/learningthehardway.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learningthehardway.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learningthehardway.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learningthehardway.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learningthehardway.wordpress.com&amp;blog=3269077&amp;post=13&amp;subd=learningthehardway&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learningthehardway.wordpress.com/2008/03/26/hyperlink-controls-and-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce755b74ee116287771eb0279ff0f662?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simondfletcher</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/simpleeval.jpg" medium="image">
			<media:title type="html">Simple Eval</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/initialcode.png" medium="image">
			<media:title type="html">Initial Code</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/initialcoderesult.png" medium="image">
			<media:title type="html">Results of Initial Code</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/evalproductname1.png" medium="image">
			<media:title type="html">Eval Product Name</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/textproperty.png" medium="image">
			<media:title type="html">Text Property</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/wrong1.png" medium="image">
			<media:title type="html">First try doesn’t work</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/wrong2.png" medium="image">
			<media:title type="html">Doesn’t work either</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/right.png" medium="image">
			<media:title type="html">This works</media:title>
		</media:content>

		<media:content url="http://learningthehardway.files.wordpress.com/2008/03/finalcode.png" medium="image">
			<media:title type="html">The Final Code</media:title>
		</media:content>
	</item>
	</channel>
</rss>
