<?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/"
	>

<channel>
	<title>LegHumped.com&#187; ASP.NET &#187; Leghumped</title>
	<atom:link href="http://www.leghumped.com/blog/category/programming/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leghumped.com/blog</link>
	<description>Coding snippets, tutorials and procrastinations about C#, Java and Linux.</description>
	<lastBuildDate>Sun, 30 May 2010 14:00:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Umbraco: Breadcrumb Trail</title>
		<link>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/</link>
		<comments>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/#comments</comments>
		<pubDate>Sun, 30 May 2010 14:00:18 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[umbraco]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=410</guid>
		<description><![CDATA[I&#8217;ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet. Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1. &#60;?xml version=&#34;1.0&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet.</p>
<p>Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1.<br />
<span id="more-410"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE xsl:Stylesheet [</span>
<span style="color: #00bbdd;">	&lt;!ENTITY amp &quot;&amp;#38;&quot;&gt;</span>
    <span style="color: #009900;">&lt;!ENTITY nbsp <span style="color: #ff0000;">&quot;&amp;#x00A0;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;">&lt;!ENTITY raquo <span style="color: #ff0000;">&quot;&amp;#187;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
]&gt;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span></span>
<span style="color: #009900;">	<span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:msxml</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xslt&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:msxsl</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xslt&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:umbraco.library</span>=<span style="color: #ff0000;">&quot;urn:umbraco.library&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;msxml umbraco.library&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">omit-xml-declaration</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;currentPage&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;breadcrumb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$currentPage/ancestor::node [string(data [@alias='umbracoNaviHide']) != '1']&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;{umbraco.library:NiceUrl(@id)}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;@level != 0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #ddbb00;">&amp;raquo;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$currentPage/@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework in Mednium Trust</title>
		<link>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/</link>
		<comments>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 18:47:56 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[entity framework]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=403</guid>
		<description><![CDATA[ASP.NET and medium trust typically don&#8217;t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions. To get this working I [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET and medium trust typically don&#8217;t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions.</p>
<p>To get this working I needed to:</p>
<ol>
<li>Move the EDMX to a separate assembly.</li>
<li>Set the EDMX metadata artifact processing to <em>&#8216;Embed in output assembly&#8217;</em>.</li>
<li>Add a reference in the site.</li>
<li>Change the connection string to

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ShopEntities&quot;</span> <span style="color: #000066;">connectionString</span>=<span style="color: #ff0000;">&quot;metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=servername;Initial Catalog=dbname;User Id=username;Password=P@55word;MultipleActiveResultSets=True&amp;quot;&quot;</span> <span style="color: #000066;">providerName</span>=<span style="color: #ff0000;">&quot;System.Data.EntityClient&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</li>
</ol>
<p>Which every guide claimed would work. There&#8217;s one more step if you have custom partial entity classes (in App_Code). If so, these also need to be moved to your output assembly, as you can&#8217;t split partial classes across assemblies. Lastly, change the namespace in your partial classes to the same as your output assembly, and everything should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET: Remove from the cache using</title>
		<link>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/</link>
		<comments>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 10:09:50 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=360</guid>
		<description><![CDATA[<p>The Cache object in ASP.NET isn't like other collections, probably because it needs to be specialized so it doesn't make use of generics. Unfortunately, that makes it more difficult to work with. This small utility method removes an object from the cache by key using a predictate. You could easily modify it to compare either of the IDictionaryEnumerator's Key or Value properties.</p>
<pre lang="csharp">
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
</pre>]]></description>
			<content:encoded><![CDATA[<p>The Cache object in ASP.NET isn&#8217;t like other collections, probably because it needs to be specialized so it doesn&#8217;t make use of generics. Unfortunately, that makes it more difficult to work with. This small utility method removes an object from the cache by key using a predictate. You could easily modify it to compare either of the IDictionaryEnumerator&#8217;s Key or Value properties.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Removes an item from the cache using a Predictate to match the key.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;keyCriteria&quot;&gt;The Predictate to use for each key to determine whether the entry should be removed.&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Removes an item from the cache using a Predictate to match the key.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;keyCriteria&quot;&gt;The Predictate to use for each key to determine whether the entry should be removed.&lt;/param&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> RemoveFromCache<span style="color: #000000;">&#40;</span>Predicate<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> keyCriteria<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	IDictionaryEnumerator enuma <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">GetEnumerator</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">while</span><span style="color: #000000;">&#40;</span>enuma.<span style="color: #0000FF;">MoveNext</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>keyCriteria<span style="color: #000000;">&#40;</span>enuma.<span style="color: #0000FF;">Key</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span>enuma.<span style="color: #0000FF;">Key</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET: Data Binding with ObjectDataSource</title>
		<link>http://www.leghumped.com/blog/2009/07/09/asp-net-data-binding-with-objectdatasource/</link>
		<comments>http://www.leghumped.com/blog/2009/07/09/asp-net-data-binding-with-objectdatasource/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 19:38:57 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[databinding]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=358</guid>
		<description><![CDATA[In the past when writing forms with ASP.NET I&#8217;ve usually used an SqlDataSource when binding to controls, but I&#8217;ve been doing a lot of WPF lately. Being a desktop platform, WPF has excellent support for DataBinding, but obviously since HTTP is a stateless protocol (apart from the ViewState in ASP.NET which isn&#8217;t ideal), it&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<p>In the past when writing forms with ASP.NET I&#8217;ve usually used an SqlDataSource when binding to controls, but I&#8217;ve been doing a lot of WPF lately. Being a desktop platform, WPF has excellent support for DataBinding, but obviously since HTTP is a stateless protocol (apart from the ViewState in ASP.NET which isn&#8217;t ideal), it&#8217;s not so well suited to data binding.</p>
<p>One thing I&#8217;ve never really tried is binding an object to a form to display a single item (eg: a report). This leads to writing lots of tedious code like:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	Order theOrder <span style="color: #008000;">=</span> GetOrder<span style="color: #000000;">&#40;</span>orderId<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	litName.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> theOrder.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
	litID.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> theOrder.<span style="color: #0000FF;">ID</span><span style="color: #008000;">;</span>
	litCustomer.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> theOrder.<span style="color: #0000FF;">BillingCustomer</span>.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
	...</pre></div></div>

<p><span id="more-358"></span></p>
<p>It never occured to me to use an ObjectDataSource with a Repeater, just returning one row. Not only does it keep all the code in one place instead of superflous bits in the code-behind, it makes it easier to see which properties on the object are being used.</p>
<p>So instead of the above, you end up with:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;">&lt;asp:ObjectDataSource ID=&quot;dsOrderDetails&quot; runat=&quot;server&quot; TypeName=&quot;DatabaseHelper&quot; SelectMethod=&quot;GetOrder&quot;&gt;
	&lt;SelectParameters&gt;
		&lt;asp:Parameter Name=&quot;orderId&quot; Type=&quot;Int32&quot; DefaultValue=&quot;-1&quot; /&gt;
	&lt;/SelectParameters&gt;
&lt;/asp:ObjectDataSource&gt;
&lt;asp:Repeater ID=&quot;rptOrder&quot; runat=&quot;server&quot; DataSourceID=&quot;dsOrderDetails&quot;&gt;
	&lt;ItemTemplate&gt;
		&lt;strong&gt;Order ID: &lt;/strong&gt;&lt;asp:Literal ID=&quot;lblOrderID&quot; runat=&quot;server&quot; Text='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;ID&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' /&gt;
		&lt;strong&gt;Checkout Complete: &lt;/strong&gt;&lt;asp:Literal ID=&quot;lblPaid&quot; runat=&quot;server&quot; Text='<span style="color: #000000; font-weight: bold;">&lt;%</span># Convert.<span style="color: #9900cc;">ToBoolean</span><span style="color: #006600; font-weight:bold;">&#40;</span>Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Paid&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">??</span> <span style="color: #cc0000;">&quot;false&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">?</span> <span style="color: #cc0000;">&quot;Yes&quot;</span> <span style="color: #006600; font-weight: bold;">:</span> <span style="color: #cc0000;">&quot;No&quot;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' /&gt;
		&lt;strong&gt;Customer Name: &lt;/strong&gt;&lt;asp:Literal ID=&quot;lblCustomerName&quot; runat=&quot;server&quot; Text='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;BillingCustomer.Name&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' /&gt;
                            &lt;/div&gt;
		...
		&lt;asp:GridView ID=&quot;grdItems&quot; runat=&quot;server&quot; DataSource='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Items&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>'...</pre></div></div>

<p>Just to put those properties into context, the object might have a structure like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Order
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> ID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> Paid <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> Customer BillingCustomer <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>OrderItem<span style="color: #008000;">&gt;</span> Items <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	...</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2009/07/09/asp-net-data-binding-with-objectdatasource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster Image Loading With jQuery</title>
		<link>http://www.leghumped.com/blog/2009/07/05/faster-image-loading-with-jquery/</link>
		<comments>http://www.leghumped.com/blog/2009/07/05/faster-image-loading-with-jquery/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 06:35:13 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=357</guid>
		<description><![CDATA[Normally, if there are images on a webpage they&#8217;re there to support the content and not excessive, so you don&#8217;t have to worry about loading times. What if you need to have an undefined number though, and they happen to be high resolution like a gallery? For the last site I worked on, the client [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, if there are images on a webpage they&#8217;re there to support the content and not excessive, so you don&#8217;t have to worry about loading times. What if you need to have an undefined number though, and they happen to be high resolution like a gallery?</p>
<p>For the last site I worked on, the client wanted a gallery of 400&#215;400 pixel images to cycle in a gallery on the front page of the site. They&#8217;re about 70KB each so if you&#8217;re loading 10 or more of them in the middle of the page, they&#8217;ll slow the page load down until they&#8217;ve all totally loaded.</p>
<p>The solution I used was to add the images to the DOM <em>after</em> the rest of the content loads.</p>
<p><span id="more-357"></span></p>
<p>The site was written in ASP.NET, but I used jQuery so it applies to any project.</p>
<p>First, you need to render a list of the images to load into a variable which JavaScript can access. Ie:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">...
<span style="color: #0000FF;">cmd</span>.<span style="color: #0000FF;">CommandText</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SELECT Filename, Description FROM tblGallery WHERE Visible = '1'&quot;</span><span style="color: #008000;">;</span>
StringBuilder jqueryBuffer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;$().ready(function() {<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
jqueryBuffer.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;var galleryImages = [<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> galleryPics <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
SqlDataReader reader <span style="color: #008000;">=</span> cmd.<span style="color: #0000FF;">ExecuteReader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
JavaScriptSerializer js <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> JavaScriptSerializer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">while</span><span style="color: #000000;">&#40;</span>reader.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    galleryPics.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>js.<span style="color: #0000FF;">Serialize</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #000000;">&#123;</span> 
        filename <span style="color: #008000;">=</span> Server.<span style="color: #0000FF;">HtmlDecode</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, 
        alt <span style="color: #008000;">=</span> Server.<span style="color: #0000FF;">HtmlDecode</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> 
    <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
reader.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
jqueryBuffer.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>Utils.<span style="color: #0000FF;">Implode</span><span style="color: #000000;">&#40;</span>galleryPics, <span style="color: #666666;">&quot;,<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;];<span style="color: #008080; font-weight: bold;">\n</span> cycleGalleryPics(galleryImages);<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
ScriptManager.<span style="color: #0000FF;">RegisterStartupScript</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Page<span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;jqueryListeners&quot;</span>, jqueryBuffer.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
...</pre></div></div>

<p>Which results in the following JavaScript on the page:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> galleryImages <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Picture 1&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Caption 2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;3&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Something 3&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;4&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;etc&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;5&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;filename&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;6&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  cycleGalleryPics<span style="color: #009900;">&#40;</span>galleryImages<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The <em>cycleGalleryPics</em> method just iterates over the array and creates an image for each element, then adds it to a named container on the document.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> cycleGalleryPics<span style="color: #009900;">&#40;</span>galleryImages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> galleryDiv <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#Gallery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    galleryDiv.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> path <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>imagePath<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        path <span style="color: #339933;">=</span> <span style="color: #3366CC;">'UserImages/Gallery/'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        path <span style="color: #339933;">=</span> imagePath <span style="color: #339933;">+</span> <span style="color: #3366CC;">'/Gallery/'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    jQuery.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>galleryImages<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img/&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            width<span style="color: #339933;">:</span> <span style="color: #CC0000;">368</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">370</span><span style="color: #339933;">,</span>
            alt<span style="color: #339933;">:</span> unescape<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">alt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            src<span style="color: #339933;">:</span> path <span style="color: #339933;">+</span> unescape<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">filename</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.jpg'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#Gallery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    galleryDiv.<span style="color: #660066;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> fx<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fade'</span><span style="color: #339933;">,</span> timeout<span style="color: #339933;">:</span> <span style="color: #CC0000;">3000</span><span style="color: #339933;">,</span> random<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> fit<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> containerResize<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The reason the contents of the container are cleared before adding the images is to provide support for users with JavaScript disabled. One image is added by an ASP.NET <em>Image</em> control so there won&#8217;t be a block of empty space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2009/07/05/faster-image-loading-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GridView with Dynamic Columns</title>
		<link>http://www.leghumped.com/blog/2008/11/22/gridview-with-dynamic-columns/</link>
		<comments>http://www.leghumped.com/blog/2008/11/22/gridview-with-dynamic-columns/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 21:20:47 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[gridview]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=335</guid>
		<description><![CDATA[The ASP.NET GridView control can be a really useful control for displaying and editing tabular data, but if you try to make it work with MySQL or a cross-tab query you&#8217;re likely to run into problems. I wanted to create a grid showing the data from a cross-tab but also allow users to edit the [...]]]></description>
			<content:encoded><![CDATA[<p>The ASP.NET GridView control can be a really useful control for displaying and editing tabular data, but if you try to make it work with MySQL or a <a href="http://leghumped.com/blog/2008/11/16/crosstab-queries/">cross-tab query</a> you&#8217;re likely to run into problems.</p>
<p>I wanted to create a grid showing the data from a cross-tab but also allow users to edit the data. If you&#8217;ve never used one before, a cross tabulation is a query which maps repeating rows to columns instead. This means that a column in a displayed result might not actually exist as a column in a database table. If you just need to display the data and aren&#8217;t bothered about editing it, the GridView works out of the box and will automatically generate the columns for you &#8211; but what if you need to display some columns but not others?</p>
<p><span id="more-335"></span></p>
<p>In my example, there are three static columns and a user specified number of dynamic ones. The static columns are coded in the .aspx page but the dynamic ones are generated by an AutoFieldGenerator which takes selections from a ListBox into account. The columns in the crosstab are populated from the selected ListBox items so I can pass the selected items to the AutoFieldGenerator and have it create template columns which I know are present as columns in the crosstab.</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>GridView ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;grdTranslations&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span> AllowPaging<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;True&quot;</span> 
	AllowSorting<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;True&quot;</span> AutoGenerateColumns<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;false&quot;</span>
	OnRowDatabound<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;row_DataBound&quot;</span> 
	OnRowCommand<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;grd_RowCommand&quot;</span> 
	OnPageIndexChanging<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;grd_PageIndexChanging&quot;</span>
	OnDataBound<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;grd_DataBound&quot;</span> PageSize<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;15&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
	<span style="color: #006600; font-weight: bold;">&lt;</span>Columns<span style="color: #006600; font-weight: bold;">&gt;</span>
	    <span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>TemplateField HeaderText<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Bundle Name&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
	        <span style="color: #006600; font-weight: bold;">&lt;</span>ItemTemplate<span style="color: #006600; font-weight: bold;">&gt;</span>
	            <span style="color: #006600; font-weight: bold;">&lt;</span>asp<span style="color: #006600; font-weight: bold;">:</span>Label ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;lblBundleName&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span> Text<span style="color: #006600; font-weight: bold;">=</span><span style="color: #008000;">'&lt;%# Eval(&quot;bundlename&quot;) %&gt;</span>' EnableViewState=&quot;False&quot;&gt;&lt;/asp:Label&gt;
	            &lt;asp:DropDownList ID=&quot;cboBundleName&quot; visible=&quot;false&quot; runat=&quot;server&quot;&gt;
	            &lt;/asp:DropDownList&gt;
	        &lt;/ItemTemplate&gt;
	    &lt;/asp:TemplateField&gt;
	    &lt;asp:TemplateField HeaderText=&quot;Element Name&quot;&gt;
	        &lt;ItemTemplate&gt;
	            &lt;asp:Label ID=&quot;lblElementName&quot; runat=&quot;server&quot; Text='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;elementname&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' EnableViewState=&quot;False&quot;&gt;&lt;/asp:Label&gt;
	            &lt;asp:TextBox ID=&quot;txtElementName&quot; runat=&quot;server&quot; Text='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;elementname&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' Visible=&quot;false&quot; EnableViewState=&quot;False&quot;&gt;&lt;/asp:TextBox&gt;
	        &lt;/ItemTemplate&gt;
	    &lt;/asp:TemplateField&gt;
	    &lt;asp:TemplateField HeaderText=&quot;Actions&quot;&gt;
	        &lt;ItemTemplate&gt;
	            &lt;asp:Button ID=&quot;btnEdit&quot; runat=&quot;server&quot; Text=&quot;Edit&quot; CommandName=&quot;edittranslation&quot; CssClass=&quot;uniformbutton&quot; EnableViewState=&quot;False&quot; /&gt;
	            &lt;asp:DropDownList ID=&quot;cboTranslationID&quot; visible=&quot;false&quot; runat=&quot;server&quot;
	                DataSourceID=&quot;dsTranslationID&quot; DataTextField=&quot;display&quot; DataValueField=&quot;translationid&quot; 
	                AppendDataBoundItems=&quot;true&quot;
	                SelectedValue='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;translationid&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>'&gt;
	                &lt;asp:ListItem Text=&quot;New Translation&quot; Value=&quot;-1&quot;&gt;&lt;/asp:ListItem&gt;
	            &lt;/asp:DropDownList&gt;
	            &lt;asp:Button ID=&quot;btnSave&quot; Visible=&quot;false&quot; runat=&quot;server&quot; Text=&quot;Save&quot; CommandName=&quot;savetranslation&quot; CommandArgument='<span style="color: #000000; font-weight: bold;">&lt;%</span># Eval<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;id&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>' /&gt;
	        &lt;/ItemTemplate&gt;
	    &lt;/asp:TemplateField&gt;
	&lt;/Columns&gt;
	&lt;/asp:GridView&gt;
%&gt;</pre></div></div>

<p>The dynamic columns are added on every postback by setting the AutoColumnGenerator property of the GridView. The source for the column generator and template are available <a href="http://leghumped.com/LanguageColumnGenerator.cs">here</a> and <a href="http://leghumped.com/GridViewTemplate.cs">here</a>. The item template is just a label and a textbox which databind themselves to the column in the DataSource with the column name given in the GridViewTemplate constructor.</p>
<p>Seem simple so far? Good, because getting the data out of the textboxes isn&#8217;t so easy. The problem exists because once you start adding columns dynamically, the GridView doesn&#8217;t seem to recognize that extra columns were added to it when the page posts back, so there&#8217;s no way to access the textbox controls in those columns. In my example, there&#8217;s an edit button and a save button in cell 3. When the edit button is clicked the page posts back and there&#8217;s a method which resets the column generator, re-databinds the GridView then finds the index of row where the edit button was clicked and changes the visibility of the edit controls.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> grd_RowCommand<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, GridViewCommandEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        GridViewRow row<span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">// The row which has clicked was the undatabound one, so use it's index to lookup the new, databound row</span>
        grdTranslations.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	row <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">CommandSource</span> <span style="color: #0600FF;">as</span> WebControl<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">NamingContainer</span> <span style="color: #0600FF;">as</span> GridViewRow<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this is the row before dynamic columns were added, only controls coded in the .aspx page are accessible as only the static columns are present.</span>
        <span style="color: #FF0000;">string</span> selectedTranslationID <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>editButtonColumNo<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cboTranslationID&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> DropDownList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedValue</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">switch</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">CommandName</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;edittranslation&quot;</span><span style="color: #008000;">:</span>
			GridViewRow newRow <span style="color: #008000;">=</span> grdTranslations.<span style="color: #0000FF;">Rows</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">CommandSource</span> <span style="color: #0600FF;">as</span> WebControl<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">NamingContainer</span> <span style="color: #0600FF;">as</span> GridViewRow<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">RowIndex</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
			<span style="color: #008080; font-style: italic;">// use the row's index to lookup the instance of the row in the new, databound GridView with dynamic columns</span>
			ShowEditControls<span style="color: #000000;">&#40;</span>row<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			break<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;savetranslation&quot;</span><span style="color: #008000;">:</span> <span style="color: #008080; font-style: italic;">// 'Save' button clicked</span>
			row <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">CommandSource</span> <span style="color: #0600FF;">as</span> WebControl<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">NamingContainer</span> <span style="color: #0600FF;">as</span> GridViewRow<span style="color: #008000;">;</span>
			SaveTranslation<span style="color: #000000;">&#40;</span>row<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// the new, databound row isn't much use as it just contains the values as the exist when the server sent them</span>
			break<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> ShowEditControls<span style="color: #000000;">&#40;</span>GridViewRow row<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cboBundleName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> DropDownList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;txtElementName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> TextBox<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>editButtonColumNo<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cboTranslationID&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> DropDownList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">RowType</span> <span style="color: #008000;">==</span> DataControlRowType.<span style="color: #0000FF;">DataRow</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	    <span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lblBundleName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> Label<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
	    <span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lblElementName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> Label<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
	    <span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>editButtonColumNo<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;btnEdit&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> Button<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
	    <span style="color: #000000;">&#40;</span>row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>editButtonColumNo<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;btnSave&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> Button<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
	    <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> editButtonColumNo <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> row.<span style="color: #0000FF;">Cells</span>.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	        row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Controls</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
	        row.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Controls</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
	    <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So all of the labels are hidden and instead, textboxes and combo boxes are shown to allow the user to edit the record. To record the user&#8217;s input when the save button is clicked, the GridView isn&#8217;t much help. The only way I could find of getting the values back out from the textboxes was to loop through Request.Form and compare the keys against the UniqueIDs of the textboxes I needed.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">...
<span style="color: #FF0000;">string</span> bundleName <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>oldRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cboBundleName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> DropDownList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedValue</span>,
                   elementName <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>oldRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;txtElementName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> TextBox<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Text</span>,
                   elementComment <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>oldRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;txtElementComment&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> TextBox<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Text</span>,
                   translationID <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>oldRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cboTranslationID&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> DropDownList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedValue</span>,
                   translationComment <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>oldRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;txtTranslationComment&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> TextBox<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> editButtonColumNo <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> newRow.<span style="color: #0000FF;">Cells</span>.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">string</span> textBoxID <span style="color: #008000;">=</span> newRow.<span style="color: #0000FF;">Cells</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Controls</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">UniqueID</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key <span style="color: #0600FF;">in</span> Request.<span style="color: #0000FF;">Form</span>.<span style="color: #0000FF;">AllKeys</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>key <span style="color: #008000;">==</span> textBoxID<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			cmd.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;@trans&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> Request.<span style="color: #0000FF;">Form</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
			cmd.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;@lang&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> textBoxID.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span>textBoxID.<span style="color: #0000FF;">LastIndexOf</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;$&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// the ID of the textbox has $country-CODE appended to it</span>
			cmd.<span style="color: #0000FF;">ExecuteNonQuery</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			break<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In my particular scenario, I needed the names of the columns as parameters for a query, which is why I stored the column names in the textbox IDs during databinding on the texbox controls in GridViewTemplate. This might not be the nicest or most efficient method of extracting the values again, but it does the job. Even with 12 dynamic textboxes and a few hidden fields the total size of the Request.Form collection was 31 keys, which won&#8217;t hamper performance too much.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2008/11/22/gridview-with-dynamic-columns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross page request variables in ASP.NET</title>
		<link>http://www.leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/</link>
		<comments>http://www.leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 14:48:07 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[master pages]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=333</guid>
		<description><![CDATA[If you have a page which uses a master page, then put controls inside a ContentPlaceHolder on the sub page, accessing the values of the controls can be difficult if you&#8217;re posting the form to another page. The problem is, the ContentPlaceHolder mangles the control names so instead of radApplication, you get ctl00$cntMain$radApplication, meaning you [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a page which uses a master page, then put controls inside a ContentPlaceHolder on the sub page, accessing the values of the controls can be difficult if you&#8217;re posting the form to another page. The problem is, the ContentPlaceHolder mangles the control names so instead of <em>radApplication</em>, you get <em>ctl00$cntMain$radApplication</em>, meaning you can&#8217;t read them from Request.Form. </p>
<p>Hardcoding the name of the placeholder would be a bad idea incase you ever change the name of it or change the master page. There are actually two ways you can get at the controls.</p>
<p><span id="more-333"></span></p>
<p>The first way, which works if you just need access to the value posted involves looping through Request.Form.AllKeys to find the name of the control.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">string</span> appName <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key <span style="color: #0600FF;">in</span> Request.<span style="color: #0000FF;">Form</span>.<span style="color: #0000FF;">AllKeys</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>key.<span style="color: #0000FF;">endsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;radApplication&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    appName <span style="color: #008000;">=</span> Request.<span style="color: #0000FF;">Form</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>While this works, it could break if there were several controls with similar names on the page. The second method uses the PreviousPage property to provide a reference to the actual control.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ContentPlaceHolder previous <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ContentPlaceHolder<span style="color: #000000;">&#41;</span>PreviousPage.<span style="color: #0000FF;">Master</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cntMain&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">string</span> projectID <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>previous.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;radApplication&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> RadioButtonList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedValue</span><span style="color: #008000;">;</span></pre></div></div>

<p>The benefit of getting a reference to the actual control is that you can see more than just the value submitted on the form.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
