<?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>Finite Epiphany &#187; webforms</title>
	<atom:link href="http://finite.mikeandcorinne.com/category/webforms/feed/" rel="self" type="application/rss+xml" />
	<link>http://finite.mikeandcorinne.com</link>
	<description>Mike&#039;s thoughts on programming and tech</description>
	<lastBuildDate>Fri, 05 Mar 2010 23:28:51 +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>An indexed foreach for .aspx Web Forms</title>
		<link>http://finite.mikeandcorinne.com/2008/03/an-indexed-foreach-for-aspx-web-forms/</link>
		<comments>http://finite.mikeandcorinne.com/2008/03/an-indexed-foreach-for-aspx-web-forms/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 17:21:37 +0000</pubDate>
		<dc:creator>Mike Thomas</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[webforms]]></category>

		<guid isPermaLink="false">http://www.mikeandcorinne.com/finite/2008/03/11/an-indexed-foreach-for-aspx-web-forms/</guid>
		<description><![CDATA[ Nick blogged about why ASP.Net Repeaters Suck the other week and talked about using foreach loops in your .aspx.  I love this and have been doing it for a while &#8211; the strong typing and consice syntax is great.  However, sometimes I need format data based on odd and even rows&#8230;  &#60;table&#62; &#60;tr class='Row'&#62;&#60;td&#62;&#60;/td&#62;&#60;/tr&#62;   [...]]]></description>
			<content:encoded><![CDATA[<p> Nick blogged about why<span style="text-decoration: underline"> </span><a href="http://www.nickandgrace.com/code/archive/2008/03/03/asp.net-repeaters-suck.aspx#feedback">ASP.Net Repeaters Suck</a> the other week and talked about using foreach loops in your .aspx.  I love this and have been doing it for a while &#8211; the strong typing and consice syntax is great.  However, sometimes I need format data based on odd and even rows&#8230;</p>
<pre> &lt;table&gt;</pre>
<pre>   &lt;tr class='Row'&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;</pre>
<pre>   &lt;tr class='AltRow'&gt;...&lt;/tr&gt;</pre>
<pre>&lt;/table&gt;</pre>
<p>To accomplish this I created a helper function in the page code behind:</p>
<pre>protected void Foreach&lt;T&gt;(IEnumerable&lt;T&gt; enumerable, Proc&lt;T, int&gt; action){</pre>
<pre> int i = 0;</pre>
<pre> foreach(T t in enumerable){</pre>
<pre>    action(t, i);</pre>
<pre>  i++</pre>
<pre>}</pre>
<pre>}</pre>
<p>Then in the .aspx</p>
<pre>&lt;%Foreach(People, (person, i) =&gt; { %&gt;</pre>
<pre>  &lt;tr class='&lt;%=i%2==0 ?  "Row" : "AltRow"%&gt;'&gt;&lt;td&gt;&lt;%=person.FullName%&gt;&lt;/td&gt;&lt;/tr&gt;</pre>
<pre>&lt;%});%&gt;</pre>
<pre></pre>
<p>Just what I needed!</p>
]]></content:encoded>
			<wfw:commentRss>http://finite.mikeandcorinne.com/2008/03/an-indexed-foreach-for-aspx-web-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
