<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6212515559541223786</id><updated>2026-07-26T08:20:58.974-07:00</updated><category term="ASP.NET"/><category term="Data Controls"/><category term="LINQ"/><category term="Language"/><category term="WinForm"/><category term="File"/><category term="TFS"/><category term="Registry"/><category term="ADO.NET"/><category term="Collections"/><category term="MVC"/><category term="Razor"/><category term="Reflection"/><category term="Regex"/><category term="Reporting"/><category term="WPF"/><title type='text'>C# and ASP.NET Code</title><subtitle type='html'>C# and .NET tips and code snippets</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>53</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5505385990923564599</id><published>2014-12-15T08:48:00.000-08:00</published><updated>2014-12-15T08:50:10.787-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="Razor"/><title type='text'>Editor Template for Boolean Property in Razor</title><content type='html'>If you want to display 2 radio buttons for a boolean property in Razor with Yes and No labels, this is how you could do it.&lt;br /&gt;
&lt;br /&gt;
Create your own editor template and put it in the Shared/EditorTemplate folder.&lt;br /&gt;
&lt;br /&gt;
Template code:&lt;br /&gt;
&lt;br /&gt;
@model bool&lt;br /&gt;
@using System.Web.Mvc&lt;br /&gt;
@Html.RadioButtonFor(model=&amp;gt;model, false) No&lt;br /&gt;
@Html.RadioButtonFor(model =&amp;gt; model, true) Yes&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5505385990923564599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2014/12/editor-template-for-boolean-property-in.html#comment-form' title='16 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5505385990923564599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5505385990923564599'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2014/12/editor-template-for-boolean-property-in.html' title='Editor Template for Boolean Property in Razor'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>16</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-3117767944005195085</id><published>2014-10-23T07:20:00.001-07:00</published><updated>2014-10-23T07:21:52.649-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><title type='text'>Create Separate Dropdowns for Day, Month, Year in ASP.NET MVC</title><content type='html'>Create a structure that will hold the Month, Day and Year fields:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;struct&lt;/span&gt; DatePart
    &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
        &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; DayItems
        &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
            get
            &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;return&lt;/span&gt; Enumerable&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Range&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;31&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
        &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;

        &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; MonthItems
        &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;

            get
            &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;new&lt;/span&gt; System&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Globalization&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;DateTimeFormatInfo&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;MonthNames&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
        &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;

        &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;static&lt;/span&gt; IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; YearItems
        &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
            get
            &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;return&lt;/span&gt; Enumerable&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Range&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;DateTime&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Now&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Year &lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;30&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
        &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
    &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;Your model class should contain the following properties;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt; Day &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt; get&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; set&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt; Month &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt; get&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; set&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;int&lt;/span&gt; Year &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt; get&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; set&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Create &lt;b&gt;SelectListItem&lt;/b&gt; Date, Month and Year collections and add them to the &lt;b&gt;ViewBag&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;pre&gt;ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Days &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; DatePart&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;DayItems&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Select&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;d &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;new&lt;/span&gt; SelectListItem &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt; Text &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; d&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;ToString&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;

 ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Months &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; DatePart&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;MonthItems&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Select&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;m&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;new&lt;/span&gt; SelectListItem
 &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
    Value &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;i &lt;span style=&quot;color: #308080;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;ToString&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;
    Text &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; m
 &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;

 ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Years &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; DatePart&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;YearItems&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Select&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;y &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;new&lt;/span&gt; SelectListItem &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt; Text &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; y&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;ToString&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;In the view, create dropdowns and populate them with collections in the ViewBag.&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;pre&gt;@Html&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;DropDownList&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;Day&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;SelectListItem&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Days&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;
@Html&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;DropDownList&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;Month&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;SelectListItem&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Months&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;
@Html&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;DropDownList&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;Year&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;IEnumerable&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt;SelectListItem&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; ViewBag&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Years&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;It is important that the select element names match the property names in the model. &lt;/br&gt;&lt;br /&gt;
Now, in your controller method you can access the selected values as follows:&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;pre&gt;var selectedTime &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;new&lt;/span&gt; DateTime&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;model&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Year&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; model&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Month&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; model&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;Day&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/3117767944005195085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2014/10/create-separate-dropdowns-for-day-month.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3117767944005195085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3117767944005195085'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2014/10/create-separate-dropdowns-for-day-month.html' title='Create Separate Dropdowns for Day, Month, Year in ASP.NET MVC'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-346493526584432182</id><published>2014-02-27T08:25:00.000-08:00</published><updated>2014-12-30T08:39:03.757-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>Replace foreach with Extension Methods and Lambda Expressions</title><content type='html'>I suppose many of us use the &lt;b style=&quot;color: blue;&quot;&gt;foreach &lt;/b&gt;statement very often in our code. I&#39;ll show you how to replace simple &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach &lt;/span&gt;&lt;/b&gt;statements with new &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb397687.aspx&quot;&gt;lambda expressions&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose you want to create a List &amp;lt; string&amp;gt; of names of files residing in a directory. This is how you could do it.&lt;br /&gt;
&lt;br /&gt;
Set up an array of FileInfo objects:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; filePath = &lt;span style=&quot;color: #a31515;&quot;&gt;@&quot;C:\Temp&quot;&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;DirectoryInfo&lt;/span&gt; dInfo = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;DirectoryInfo&lt;/span&gt;(filePath); &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;FileInfo&lt;/span&gt;[] fileInfoArray = dInfo.GetFiles();&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Create a string type List:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; fileList = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;FileInfo&lt;/span&gt; fi &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; fileInfoArray)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileList.Add(fi.Name);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
}&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;
Select&lt;/h3&gt;
Using lambda expressions and the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb548891%28v=VS.100%29.aspx&quot;&gt;Select &lt;/a&gt;extension method it is possible to re-write the last 3 lines as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; files = fileInfoArray.&lt;b&gt;Select&lt;/b&gt;(fi =&amp;gt; fi.Name);&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
That&#39;s one line instead of 3. But we still want a List &amp;lt;string&amp;gt; object to be used later in the code. We need to use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb342261%28v=VS.100%29.aspx&quot;&gt;Enumerable.ToList &amp;lt;TSource&amp;gt; method &lt;/a&gt;to cast to a List. This is how we do it:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; fileList2 = fileInfoArray.Select(fi =&amp;gt; fi.Name).ToList ();&amp;nbsp; &lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
This way you use one line of code instead of 4.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Modify Elements in a Collection&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Use the &lt;b&gt;Select&lt;/b&gt; method to modify elements in a collection. The important part is you need to &lt;b&gt;return &lt;/b&gt;each element;&lt;br /&gt;
&lt;br /&gt;
An example follows:&lt;br /&gt;
&lt;br /&gt;
var plans = query.&lt;b&gt;AsEnumerable&lt;/b&gt;().Select(it =&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; it.PlanYears = Enumerable.Range(it.Plan.StartDate.Year, (DateTime.Now.Year - it.Plan.StartDate.Year) + 1); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;return &lt;/b&gt;it;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How to get an ordinal position of an item in the list.&lt;/b&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharp&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #0600ff; font-weight: bold;&quot;&gt;var&lt;/span&gt; mm &lt;span style=&quot;color: green;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;System.&lt;span style=&quot;color: blue;&quot;&gt;Globalization&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;DateTimeFormatInfo&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;MonthNames&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0600ff; font-weight: bold;&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;(&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;(&lt;/span&gt;a, i&lt;span style=&quot;color: green;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;new&lt;/span&gt;
                    &lt;span style=&quot;color: green;&quot;&gt;{&lt;/span&gt;
                        Item &lt;span style=&quot;color: green;&quot;&gt;=&lt;/span&gt; a,
                        Position &lt;span style=&quot;color: green;&quot;&gt;=&lt;/span&gt; i
                    &lt;span style=&quot;color: green;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
Where&lt;/h3&gt;
Now, what if we add only those file names to the List that meet certain criteria, e.g:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;FileInfo&lt;/span&gt; fi &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; fileInfoArray)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (fi.Length &amp;gt; 10000000)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; largeFiles.Add(fi.Name);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Which equivalent extension method can we use to achieve the same result? We need to use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb534803%28v=VS.100%29.aspx&quot;&gt;Where&lt;/a&gt; extension method of the IEnumerable &amp;lt;T&amp;gt; interface first, and then append the earlier Select method to the statement:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; varLargeFiles =&amp;nbsp; fileInfoArray.&lt;b&gt;Where &lt;/b&gt;(fi =&amp;gt; fi.Length &amp;gt; 1000000).Select(fi=&amp;gt;fi.Name);&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin: 2px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//&lt;/script&gt;
&lt;/div&gt;
--&amp;gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
FindAll&lt;/h3&gt;
If you need to filter your collection and iterate through the result, use the &lt;b&gt;FindAll &lt;/b&gt;extension:&lt;br /&gt;
&lt;br /&gt;
IncomeSourceList.FindAll(item =&amp;gt; item.ItemSourceType == SourceType.PERM).ForEach(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item =&amp;gt; Debug.WriteLine(item.ItemSourceType)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;br /&gt;
&lt;br /&gt;
This code selects only those collection items whose ItemSourceType equals to PERM type, and then loops through the result.&lt;br /&gt;
&lt;h3&gt;
LINQ&lt;/h3&gt;
Now, to complete the example, I&#39;ll show the way to obtain a similar list using the &lt;a href=&quot;http://msdn.microsoft.com/library/bb308959.aspx&quot;&gt;&lt;b&gt;LINQ&lt;/b&gt;&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; q = &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; fi &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; fileInfoArray&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; fi.Length &amp;gt; 1000000&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;select&lt;/span&gt; fi.Name;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; largeFiles2 = q.ToList();&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Query operator &lt;b&gt;ToList()&amp;nbsp;&lt;/b&gt;forces immediate query evaluation.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Boolean Methods &lt;/b&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;br /&gt;
What if you have a method that loops through an array and returns a &lt;b&gt;bool &lt;/b&gt;type depending on some condition inside the loop. Can we use query operators instead? It is slightly more difficult but still possible.&lt;br /&gt;
&lt;br /&gt;
Suppose you have the following methods that compares each character in a string array to each character in another string array and returns false when a character in the second array is not found in the first array:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;IsAnagram&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;word&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;input&lt;span style=&quot;font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;[] &lt;/span&gt;inputArray&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;input.ToCharArray&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;ch&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;word.ToCharArray&lt;span style=&quot;font-weight: bold;&quot;&gt;())&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;!inputArray.Contains&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;ch&lt;span style=&quot;font-weight: bold;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
To emulate similar statements, first we need to find the first non-matching character:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;c&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &lt;/span&gt;word.ToCharArray&lt;span style=&quot;font-weight: bold;&quot;&gt;()&lt;/span&gt;.FirstOrDefault&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;x&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&amp;gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;!inputArray.Contains&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;x&lt;span style=&quot;font-weight: bold;&quot;&gt;));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&amp;nbsp;We use the &lt;i&gt;&lt;b&gt;FirstOrDefault&amp;nbsp; &lt;/b&gt;&lt;/i&gt;operator instead of &lt;b&gt;&lt;i&gt;First &lt;/i&gt;&lt;/b&gt;because otherwise we may have &quot;Sequence contains no matching element&quot; error if the expression does not returns any characters. &lt;br /&gt;
&lt;br /&gt;
Now we can return a &lt;b&gt;bool &lt;/b&gt;value depending on the result of the previous statement:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;c&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;!=&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;0&lt;span style=&quot;font-weight: bold;&quot;&gt;) &lt;/span&gt;?&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
For sheer fun you can rewrite those two statements as follows:&amp;nbsp; &lt;br /&gt;
&lt;div style=&quot;background-color: white; background-position: initial initial; background-repeat: initial initial; padding: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;word.ToCharArray&lt;span style=&quot;font-weight: bold;&quot;&gt;()&lt;/span&gt;.FirstOrDefault&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;x&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&amp;gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;!inputArray.Contains&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;x&lt;span style=&quot;font-weight: bold;&quot;&gt;))) &lt;/span&gt;==&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;0&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;
&lt;strong style=&quot;font-family: Consolas; font-size: 14.44444465637207px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Grouping&lt;/span&gt;&lt;/strong&gt;&lt;/h4&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;Grouping allows us to group the result into distinct groups using a field or several fields as group criteria. Each group will have a key property that you can use to refer to the field(s) grouped on.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;Example:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;&amp;nbsp;Let&#39;s say we have a Sales table with the following fields: Rep, SalesDate, RepEmail, etc. We&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 14.44444465637207px;&quot;&gt;&amp;nbsp;want to know how many sales each Rep made each month.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;First, let&#39;s build a query that counts the total number of sales per Rep:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #002240; color: white;&quot;&gt;&lt;span style=&quot;color: #ff9d00;&quot;&gt;from&lt;/span&gt; s &lt;span style=&quot;color: #ff9d00;&quot;&gt;in&lt;/span&gt; Sales
group s by &lt;span style=&quot;color: #ff628c;&quot;&gt;s&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Rep&lt;/span&gt; into gr
&lt;span style=&quot;color: #ff9d00;&quot;&gt;select&lt;/span&gt; new {
    Name &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff628c;&quot;&gt;gr&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Key&lt;/span&gt;,
    Count &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff628c;&quot;&gt;gr&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Count&lt;/span&gt;()
}

&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;This query would translate into the following sql statement:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #002240; color: white;&quot;&gt;&lt;span style=&quot;color: #ff9d00;&quot;&gt;select&lt;/span&gt; Rep &lt;span style=&quot;color: #ff9d00;&quot;&gt;as&lt;/span&gt; Name, &lt;span style=&quot;color: #ffb054;&quot;&gt;Count&lt;/span&gt;(&lt;span style=&quot;color: #ff9d00;&quot;&gt;*&lt;/span&gt;)
    &lt;span style=&quot;color: #ff9d00;&quot;&gt;from&lt;/span&gt; Sales
    &lt;span style=&quot;color: #ff9d00;&quot;&gt;Group By&lt;/span&gt; Rep
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 14.44444465637207px;&quot;&gt;To group the result further by month, we would use the following query:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #002240; color: white;&quot;&gt;&lt;span style=&quot;color: #ff9d00;&quot;&gt;from&lt;/span&gt; s &lt;span style=&quot;color: #ff9d00;&quot;&gt;in&lt;/span&gt; Sales
group s by new {&lt;span style=&quot;color: #ff628c;&quot;&gt;s&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Rep&lt;/span&gt;, &lt;span style=&quot;color: #ff628c;&quot;&gt;s&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;SalesDate&lt;/span&gt;.Month} 
into gr
&lt;span style=&quot;color: #ff9d00;&quot;&gt;select&lt;/span&gt; new {
    Name &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff628c;&quot;&gt;gr&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Key&lt;/span&gt;.Rep,
    SalesMonth &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff628c;&quot;&gt;gr&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Key&lt;/span&gt;.Month,
    Count &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff628c;&quot;&gt;gr&lt;/span&gt;.&lt;span style=&quot;color: #ff628c;&quot;&gt;Count&lt;/span&gt;()
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Sorting&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
This does not really belong in this post, however, here is a quick way to sort a list of objects. Your object could be similar to this one:&lt;/div&gt;
&lt;div style=&quot;color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #002240; color: white;&quot;&gt;&lt;span style=&quot;color: #ffee80;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #ffdd00;&quot;&gt;MyObject&lt;/span&gt;{
   &lt;span style=&quot;color: #ff9d00;&quot;&gt;public&lt;/span&gt; string Symbol {&lt;span style=&quot;color: #ffb054;&quot;&gt;get&lt;/span&gt;;&lt;span style=&quot;color: #ffb054;&quot;&gt;set&lt;/span&gt;;}
   &lt;span style=&quot;color: #ff9d00;&quot;&gt;public&lt;/span&gt; double Value {&lt;span style=&quot;color: #ffb054;&quot;&gt;get&lt;/span&gt;;&lt;span style=&quot;color: #ffb054;&quot;&gt;set&lt;/span&gt;;}
}

myList.Sort((a, b) &lt;span style=&quot;color: #ff9d00;&quot;&gt;=&lt;/span&gt;&amp;gt; a.Symbol.CompareTo(b.Symbol));
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong style=&quot;font-family: Consolas; font-size: 14.5454540252686px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Any&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
To find out if an element exists in a collection, use the extension method &lt;b&gt;Any&lt;/b&gt;:&lt;br /&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;   if(userRoles.&lt;b&gt;Any&lt;/b&gt;(role=&amp;gt; role.Equals(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Admin&quot;&lt;/span&gt;)))&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;        ...&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: purple;&quot;&gt;Some other posts you might find interesting:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; background-position: initial initial; background-repeat: initial initial; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;a href=&quot;http://c-sharpe.blogspot.ca/2010/06/extension-method-first.html&quot; target=&quot;_blank&quot;&gt;Query Operator First&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; background-position: initial initial; background-repeat: initial initial; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;a href=&quot;http://c-sharpe.blogspot.ca/2009/06/easy-syntax-to-print-list-elements.html&quot; target=&quot;_blank&quot;&gt;Easy Syntax to Print List Elements&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; background-position: initial initial; background-repeat: initial initial; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/346493526584432182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/05/replace-foreach-with-lambda.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/346493526584432182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/346493526584432182'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/05/replace-foreach-with-lambda.html' title='Replace foreach with Extension Methods and Lambda Expressions'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5713904756081609651</id><published>2013-09-04T06:22:00.003-07:00</published><updated>2013-09-04T06:23:10.805-07:00</updated><title type='text'>Deploy ASP MVC on IIS 6</title><content type='html'>This post just complements information already available online.&lt;br /&gt;
There are certain steps you need to do first before your ASP MVC application can run in IIS 6.&lt;br /&gt;
&lt;br /&gt;
In the &lt;b&gt;Properties &lt;/b&gt;screen, on the &lt;b&gt;Directory &lt;/b&gt;tab click &lt;b&gt;Configuration&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9l9padVv6-7l2z8KkQbGQT7lPqaFsjcncAx9ev17x6vrTrAh5No3vY4bWzBvf0T0JeVQIBZCKxAXz2QPUS8svmacHJuG18caMKJpEFJeCipQmErpFStvdwO5wvp1iOpxlmX3-m0w1oOk/s1600/config1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9l9padVv6-7l2z8KkQbGQT7lPqaFsjcncAx9ev17x6vrTrAh5No3vY4bWzBvf0T0JeVQIBZCKxAXz2QPUS8svmacHJuG18caMKJpEFJeCipQmErpFStvdwO5wvp1iOpxlmX3-m0w1oOk/s320/config1.png&quot; width=&quot;290&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
On the &lt;b&gt;Mappings &lt;/b&gt;tab, click &lt;b&gt;Insert&lt;/b&gt; to insert a wildcard application map:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3nn_e85ir6XfUYHQMXwANUmN3ymjq1xhmJLlTGxRAyA4V5Rf7qVjhHdvQkyxPp56hm8wz9340Ov1pZSqdFflpxjLm6_59DH703bSUzDdEIA6NIG0mjVtI0P2AfAM5WnmHxDUBJhNCFNI/s1600/ExtensionMapping.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;97&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3nn_e85ir6XfUYHQMXwANUmN3ymjq1xhmJLlTGxRAyA4V5Rf7qVjhHdvQkyxPp56hm8wz9340Ov1pZSqdFflpxjLm6_59DH703bSUzDdEIA6NIG0mjVtI0P2AfAM5WnmHxDUBJhNCFNI/s320/ExtensionMapping.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Browse to the location of the aspnet_isapi.dll file. Make sure that &lt;b&gt;Verify that file exists&lt;/b&gt; check-box is clear.&lt;br /&gt;
&lt;br /&gt;
Click OK to save your changes. That should be enough provided you have all the required dll files in the bin folder.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5713904756081609651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2013/09/deploy-asp-mvc-on-iis-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5713904756081609651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5713904756081609651'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2013/09/deploy-asp-mvc-on-iis-6.html' title='Deploy ASP MVC on IIS 6'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9l9padVv6-7l2z8KkQbGQT7lPqaFsjcncAx9ev17x6vrTrAh5No3vY4bWzBvf0T0JeVQIBZCKxAXz2QPUS8svmacHJuG18caMKJpEFJeCipQmErpFStvdwO5wvp1iOpxlmX3-m0w1oOk/s72-c/config1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-7579378266766222962</id><published>2013-07-18T11:17:00.002-07:00</published><updated>2013-07-18T11:17:38.422-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reflection"/><title type='text'>Copy Property Values</title><content type='html'>If you have 2 objects that do not inherit from each other but have similar properties, here is a function you can use to copy property values from one object to the other:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public static void CopyIdenticalProperties (this object source, object dest)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var plist = from prop in source.GetType().GetProperties()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where prop.CanRead &amp;amp;&amp;amp; prop.CanWrite&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select prop;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (PropertyInfo prop in plist)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var destProp = dest.GetType().GetProperty(prop.Name); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (destProp != null)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; destProp.SetValue(dest, prop.GetValue(source, null), null);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;/code&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/7579378266766222962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2013/07/copy-property-values.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/7579378266766222962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/7579378266766222962'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2013/07/copy-property-values.html' title='Copy Property Values'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-2320846491165600310</id><published>2013-06-12T12:00:00.000-07:00</published><updated>2013-06-12T12:01:13.490-07:00</updated><title type='text'>Format Phone Number</title><content type='html'>This is how you could format a phone number using a period as a separator:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;String.Format&lt;/span&gt;(&lt;span style=&quot;color: #666666;&quot;&gt;&quot;{0:###\\.###\\.####}&quot;&lt;/span&gt;, 1234567890);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The resulting string will look as follows: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;123.456.7890.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/2320846491165600310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2013/06/format-phone-number.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/2320846491165600310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/2320846491165600310'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2013/06/format-phone-number.html' title='Format Phone Number'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-3791545487106324086</id><published>2012-11-28T10:30:00.001-08:00</published><updated>2012-11-28T10:32:59.624-08:00</updated><title type='text'>Update WCF Service Site References</title><content type='html'>If you have a problem updating&amp;nbsp;dll files in the&amp;nbsp;bin folder of your Web Site deployment project, the following method may work: delete all dll files in your bin folder, and then add a reference to you Service project. All the other required dll files will be added automatically.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/3791545487106324086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2012/11/update-wcf-service-site-references.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3791545487106324086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3791545487106324086'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2012/11/update-wcf-service-site-references.html' title='Update WCF Service Site References'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-4840290253916059972</id><published>2012-05-31T13:14:00.001-07:00</published><updated>2012-06-12T10:20:27.599-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Regex"/><title type='text'>Regex for Month Number</title><content type='html'>This is the regular expressions pattern I use to test whether string characters represent a month number (from 01 to 12):&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;(0[1-9]|1[0-2])&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The expression part inside the brackets is broken into 2 possible parts divided by a vertical bar (or pipe symbol): &lt;span style=&quot;font-size: large;&quot;&gt;0[1-9] &lt;span style=&quot;font-size: small;&quot;&gt;or&lt;/span&gt; 1[0-2]&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
If a string matches any of the 2 parts it is true.&lt;br /&gt;
&lt;br /&gt;
The first one says that the 2-character string has to start with 0 and end with any number in the range from 1 to 9, e.g. &lt;em&gt;01, 02, 09&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
The second part matches any 2-character string that starts with 1 and ends with 0, 1 or 2, i.e. &lt;em&gt;10, 11, or 12&lt;/em&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/4840290253916059972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2012/05/regex-for-month-number.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/4840290253916059972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/4840290253916059972'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2012/05/regex-for-month-number.html' title='Regex for Month Number'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-143787679821733203</id><published>2012-03-12T08:00:00.000-07:00</published><updated>2012-05-14T08:45:10.922-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="File"/><title type='text'>Delete Contents of IsolatedStorageFile</title><content type='html'>The easiest way to delete contents of an IsolatedStorageFile is to open it in the Truncate mode:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;IsolatedStorageFile&lt;/span&gt; isoStore = &lt;span style=&quot;color: #2b91af;&quot;&gt;IsolatedStorageFile&lt;/span&gt;.GetUserStoreForAssembly();&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;IsolatedStorageFileStream&lt;/span&gt; isoFile = &lt;span style=&quot;color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;IsolatedStorageFileStream&lt;/span&gt;(&lt;em&gt;myFileName&lt;/em&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;FileMode&lt;/span&gt;.Truncate, isoStore);&lt;br /&gt;
&lt;br /&gt;
According to the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx&quot; target=&quot;_blank&quot;&gt;MSDN&lt;/a&gt; , if a file is opened in the Truncate&amp;nbsp;mode its size should be 0 bytes.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/143787679821733203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2012/03/delete-contents-of-isolatedstoragefile.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/143787679821733203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/143787679821733203'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2012/03/delete-contents-of-isolatedstoragefile.html' title='Delete Contents of IsolatedStorageFile'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-8229042108737382079</id><published>2011-12-02T11:17:00.001-08:00</published><updated>2012-06-12T09:58:24.450-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Delete ScriptManager History</title><content type='html'>Well, I have not found a way to clear &lt;strong&gt;ScriptManager&lt;/strong&gt; history proper, but&amp;nbsp;the workaround&amp;nbsp;&amp;nbsp;is to use the &lt;strong&gt;AddHistoryPoint&lt;/strong&gt; method and set the value of your property to &quot;0&quot;:&lt;br /&gt;
&lt;br /&gt;
ScriptManager1.AddHistoryPoint(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;myKey&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/8229042108737382079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/12/delete-scriptmanager-history.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8229042108737382079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8229042108737382079'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/12/delete-scriptmanager-history.html' title='Delete ScriptManager History'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-96341551934391541</id><published>2011-10-25T10:59:00.000-07:00</published><updated>2014-04-07T09:59:25.035-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Controls"/><title type='text'>Check if GridView Column Exists</title><content type='html'>If you have a &lt;span style=&quot;color: #2b91af;&quot;&gt;DataRowView &lt;/span&gt;you can use the following extension method to check if a GridView column exists:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;public static bool ColumnExists( &lt;span style=&quot;color: blue;&quot;&gt;this&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataRowView &lt;/span&gt;rowData,&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;string&amp;nbsp; &lt;/span&gt;fldToCheck)&lt;br /&gt;{&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: blue;&quot;&gt;return &lt;/span&gt;rowData.Row.Table.Columns.Contains(fldToCheck);&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;}&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
Normally, you would use it on RowDataBound event, e.g:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataRowView &lt;/span&gt;rowData = e.Row.DataItem as DataRowView;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&amp;nbsp; &lt;/span&gt;fldToCheck = &quot;MyFieldName&quot;;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;if (e.Row.RowType == DataControlRowType.DataRow)&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;{&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (rowData.ColumnExists(fldToCheck) ...&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
&lt;a href=&quot;http://c-sharpe.blogspot.ca/2011/10/find-gridview-column-index.html&quot; target=&quot;_blank&quot;&gt;Find GridView Column Index&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://c-sharpe.blogspot.ca/2010/10/set-datarow-values.html&quot; target=&quot;_blank&quot;&gt;Set DataRow Values and Other ASP.NET GridView Tips&lt;/a&gt;&lt;br /&gt;
&lt;h3 class=&quot;post-title entry-title&quot; itemprop=&quot;name&quot; style=&quot;background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 22px; font-weight: normal; margin: 0.75em 0px 0px; position: relative;&quot;&gt;
&lt;/h3&gt;
&lt;div style=&quot;float: left; margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/96341551934391541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/check-if-gridview-column-exists.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/96341551934391541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/96341551934391541'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/check-if-gridview-column-exists.html' title='Check if GridView Column Exists'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-8867691013118599829</id><published>2011-10-17T13:58:00.000-07:00</published><updated>2014-04-07T11:19:52.672-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Modify Query String</title><content type='html'>&lt;br /&gt;
If you build a hyperlink on a web page dynamically, sometimes you may need to append or modify an existing query string.&lt;br /&gt;
To modify a url with an existing query string, first grab the AbsoluteUrl property:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; path = Request.Url.AbsolutePath ;&lt;br /&gt;
&lt;br /&gt;
This will give you a url wihout the query string portion. &lt;br /&gt;
&lt;br /&gt;
If you need to reuse an existing portion of the query string, you have to get it yourself, e.g:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; key = Request.QueryString[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;key&quot;&lt;/span&gt;];&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; path = Request.Url.AbsolutePath + &quot;?key=&quot;+ key;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, you can build your url:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; url&amp;nbsp; = path+ &quot;&amp;amp;key2=&quot;+ myValue;&lt;br /&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
&lt;a href=&quot;http://c-sharpe.blogspot.ca/2010/11/add-javascript-dynamically-to.html&quot; target=&quot;_blank&quot;&gt;Add JavaScript Dynamically to ASP.NET UpdatePanel&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://c-sharpe.blogspot.ca/2010/07/examine-columns-in-metatable.html&quot; target=&quot;_blank&quot;&gt;Examine Columns in ASP.NET Dynamic Data MetaTable&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/8867691013118599829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/modify-query-string.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8867691013118599829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8867691013118599829'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/modify-query-string.html' title='Modify Query String'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-3269092988025444113</id><published>2011-10-13T13:21:00.000-07:00</published><updated>2012-06-12T09:59:31.559-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Controls"/><title type='text'>Find GridView Column Index</title><content type='html'>If you create G&lt;strong&gt;ridView&lt;/strong&gt; columns dynamically using the &lt;strong&gt;AutogenerateColumns&lt;/strong&gt; = true feature, sometimes you need to find a column index from the column name.&lt;br /&gt;
&lt;br /&gt;
I created an extension method to find a column index:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #ffffff; color: black;&quot;&gt;&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;int&lt;/span&gt; GetIndex&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;this&lt;/span&gt; DataRowView tableData&lt;span style=&quot;color: #808030;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;string&lt;/span&gt; fieldName&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;
        &lt;span style=&quot;color: purple;&quot;&gt;{&lt;/span&gt;
            DataColumn dc &lt;span style=&quot;color: #808030;&quot;&gt;=&lt;/span&gt; tableData&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;DataView&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;Table&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;Columns&lt;span style=&quot;color: #808030;&quot;&gt;[&lt;/span&gt;fieldName&lt;span style=&quot;color: #808030;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;
            
            &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;dc &lt;span style=&quot;color: #808030;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;
            &lt;span style=&quot;color: purple;&quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;return&lt;/span&gt; dc&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;Ordinal&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color: purple;&quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: purple;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
This is how you call from&amp;nbsp;the &lt;strong&gt;RowDataBound&lt;/strong&gt; event handler:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #ffffff; color: black;&quot;&gt;DataRowView tableData &lt;span style=&quot;color: #808030;&quot;&gt;=&lt;/span&gt; e&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;Row&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;DataItem &lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;as&lt;/span&gt; DataRowView&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;int&lt;/span&gt; pos &lt;span style=&quot;color: #808030;&quot;&gt;=&lt;/span&gt; tableData&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;GetIndex&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000e6;&quot;&gt;MyFieldName&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;                
&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;pos &lt;span style=&quot;color: #808030;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color: dimgrey;&quot;&gt;   //do your thing&lt;/span&gt;
&lt;span style=&quot;color: purple;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/3269092988025444113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/find-gridview-column-index.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3269092988025444113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3269092988025444113'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/10/find-gridview-column-index.html' title='Find GridView Column Index'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5954225423293534094</id><published>2011-07-27T13:26:00.000-07:00</published><updated>2012-04-25T17:11:50.316-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="WPF"/><title type='text'>WPF GridView Cell Borders</title><content type='html'>&lt;code&gt;The post is moved to &lt;a href=&quot;http://wpf123.blogspot.ca/2012/04/wpf-gridview-cell-borders.html&quot;&gt;this &lt;/a&gt;blog.&lt;/code&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5954225423293534094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/07/gridview-cell-borders.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5954225423293534094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5954225423293534094'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/07/gridview-cell-borders.html' title='WPF GridView Cell Borders'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5490968340014292446</id><published>2011-03-17T07:24:00.000-07:00</published><updated>2012-06-12T09:59:52.086-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Check QueryString for Null</title><content type='html'>If you need to determine whether the &lt;strong&gt;Request.QueryString&lt;/strong&gt; is null and take some action depending on the result, it is not enough to check for null. QueryString is an &lt;strong&gt;HttpValueCollection&lt;/strong&gt; type, so even if the Request.Url does not have a query string appended to it, the value of the collection&amp;nbsp;is not going to be null. The proper way to check if the query string contains anything is to check for null &lt;strong&gt;and the Count&lt;/strong&gt; property as well:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;span style=&quot;color: black;&quot;&gt;(Request.QueryString!= &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; Request.QueryString.Count&amp;gt;0){&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //some piece of code.&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5490968340014292446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2011/03/check-querystring-for-null.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5490968340014292446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5490968340014292446'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2011/03/check-querystring-for-null.html' title='Check QueryString for Null'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-7643495846573835124</id><published>2010-12-03T12:35:00.000-08:00</published><updated>2012-06-12T10:00:14.140-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Language"/><title type='text'>C# Delegates as Method Parameters</title><content type='html'>Let&#39;s say you have 2 methods that go through similar steps:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;GetPrevItem&lt;span style=&quot;font-weight: bold;&quot;&gt;()&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;&lt;b&gt;IsValidPrevEntry&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;())&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;b&gt;GetPrevString&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;SetProperties&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;GetNextItem&lt;span style=&quot;font-weight: bold;&quot;&gt;()&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;&lt;b&gt;IsValidNextEntry&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;())&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;b&gt;GetNextString&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;SetProperties&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
These 2 methods essentially do the same thing. First, they check for some condition, and if the condition evaluates to true, they call another method, set some properties, and return a string. We can use &lt;b&gt;C#&lt;/b&gt; &lt;b&gt;delegates &lt;/b&gt;to refactor these 2 methods into one. Here is how you do it:&lt;br /&gt;
Declare 2 &lt;b&gt;delegates &lt;/b&gt;whose signature matches the methods we want to replace:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;IsValid&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;GetItem&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Create a method that will use the delegates: &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;GetMyItem&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;IsValid&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;isValid&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;GetItem&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;getItem&lt;span style=&quot;font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (&lt;/span&gt;isValid&lt;span style=&quot;font-weight: bold;&quot;&gt;())&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;getItem&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;SetEventProperties&lt;span style=&quot;font-weight: bold;&quot;&gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;item&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
An alternative method signature is as follows:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;GetNavItem&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&amp;gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;isValid&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;getItem&lt;span style=&quot;font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
This way we don&#39;t have to declare delegates separately.&lt;br /&gt;
&lt;br /&gt;
Now, we can call the new method, passing the methods that we called before refactoring, as parameters:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;strPrev&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;GetMyItem&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;b&gt;IsValidPrevEntry&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;GetPrevString&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;strNext&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;=&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;GetMyItem&lt;span style=&quot;font-weight: bold;&quot;&gt;(&lt;/span&gt;&lt;b&gt;IsValidNextEntry&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;GetNextString&lt;/b&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
An interesting discussion of delegates can be found on the &lt;a href=&quot;http://stackoverflow.com/questions/2113779/can-someone-explain-this-c-lambda-syntax&quot;&gt;stackflow&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/7643495846573835124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/12/c-delegates-as-method-parameters.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/7643495846573835124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/7643495846573835124'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/12/c-delegates-as-method-parameters.html' title='C# Delegates as Method Parameters'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-3210463925577912042</id><published>2010-11-16T08:45:00.000-08:00</published><updated>2012-06-12T10:00:28.705-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Add JavaScript Dynamically to ASP.NET UpdatePanel</title><content type='html'>Use the following example:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
System.Text.&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt; sb = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; System.Text.&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt;();&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sb.Append(&lt;span style=&quot;color: #a31515;&quot;&gt;@&quot; var inputs = document.getElementsByTagName(&#39;input&#39;);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var i = 0; i &amp;lt; inputs.length; i++) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #a31515;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (inputs[i].type == &#39;text&#39;) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #a31515;&quot;&gt;inputs[i].onkeypress = function (event) {&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; event = event || window.event; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #a31515;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return myJavaScriptFunction(event);}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #a31515;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; }}&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; );&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;ScriptManager&lt;/span&gt;.&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb350750.aspx&quot;&gt;RegisterClientScriptBlock &lt;/a&gt;(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.GetType(), &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ajax&quot;&lt;/span&gt;, sb.ToString(), &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;);&amp;nbsp; &lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
What it does is attaches&amp;nbsp; a &lt;b&gt;JavaScript &lt;/b&gt;function (defined elsewhere) to each input box on the page on the key press event, and then registers it for use with a control that is inside an &lt;b&gt;UpdatePanel&lt;/b&gt;.&amp;nbsp; This could be used for user input validation. The code has been verified in IE and Firefox.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/3210463925577912042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/11/add-javascript-dynamically-to.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3210463925577912042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3210463925577912042'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/11/add-javascript-dynamically-to.html' title='Add JavaScript Dynamically to ASP.NET UpdatePanel'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5656374049706903755</id><published>2010-11-10T13:28:00.000-08:00</published><updated>2012-06-12T10:00:51.515-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Controls"/><title type='text'>ASP.NET GridView Subclass with Dynamic Footer Totals</title><content type='html'>A frequent requirement when using an &lt;b&gt;ASP.NET GridView&lt;/b&gt; on a web page is to have a footer with totals for numeric columns in the GridView. Here is a &lt;b&gt;GridView&lt;/b&gt; subclass that calculates footer totals dynamically.&amp;nbsp; It requires 3 parameters:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;FirstComputedColumnIndex&lt;/b&gt; - the for index of the first column in the data set to be computed&lt;br /&gt;
&lt;b&gt;FirstVisbleComputedColumnIndex&lt;/b&gt; - for the index of the first computed column to be shown&lt;br /&gt;
&lt;b&gt;NumberOfComput&lt;/b&gt;&lt;b&gt;edColumns&lt;/b&gt; - for the number of computed columns.&lt;br /&gt;
&lt;br /&gt;
Here is the class code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; Eric.TotalGrid {&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;partial&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;GridView&lt;/span&gt; : System.Web.UI.WebControls.&lt;span style=&quot;color: #2b91af;&quot;&gt;GridView&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Indexer footerTotals;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; FirstComputedColumnIndex { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; FirstVisbleComputedColumnIndex { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; NumberOfComputedColumns { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; OnLoad(&lt;span style=&quot;color: #2b91af;&quot;&gt;EventArgs&lt;/span&gt; e)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ShowFooter = &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;.OnLoad(e);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; OnInit(&lt;span style=&quot;color: #2b91af;&quot;&gt;EventArgs&lt;/span&gt; e)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; footerTotals = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Indexer(NumberOfComputedColumns);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;.OnInit(e);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; InitializeComponent()&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.RowDataBound += &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;GridViewRowEventHandler&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.GridView1_RowDataBound);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; GridView1_RowDataBound(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;GridViewRowEventArgs&lt;/span&gt; e)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;DataRowView&lt;/span&gt; tableData = e.Row.DataItem &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;DataRowView&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.Row.RowType == &lt;span style=&quot;color: #2b91af;&quot;&gt;DataControlRowType&lt;/span&gt;.DataRow)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i = FirstComputedColumnIndex; i &amp;lt; (FirstComputedColumnIndex + NumberOfComputedColumns); i++)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (tableData[i] != &lt;span style=&quot;color: #2b91af;&quot;&gt;DBNull&lt;/span&gt;.Value)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;decimal&lt;/span&gt; result = 0;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Decimal&lt;/span&gt;.TryParse(tableData[i].ToString(), &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; result))&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; footerTotals[i - FirstComputedColumnIndex] += result;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.Row.RowType == &lt;span style=&quot;color: #2b91af;&quot;&gt;DataControlRowType&lt;/span&gt;.Footer)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; NumberOfComputedColumns; i++)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.Row.Cells.Count &amp;gt; (i + FirstVisbleComputedColumnIndex))&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Row.Cells[i + FirstVisbleComputedColumnIndex].Text = footerTotals[i].ToString();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
The key to this GridView is using an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/2549tw02%28v=VS.100%29.aspx&quot;&gt;Indexer &lt;/a&gt;class that can be accessed like an array. Here is its listing:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Indexer&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; _upperLimit;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;decimal&lt;/span&gt;[] myArray;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Indexer(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; limit)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _upperLimit = limit;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; myArray = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;decimal&lt;/span&gt;[_upperLimit];&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;decimal&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;[&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; index]&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// Indexer declaration&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// Check the index limits.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (index &amp;lt; 0 || index &amp;gt;= _upperLimit)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; 0;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; myArray[index];&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!(index &amp;lt; 0 || index &amp;gt;= _upperLimit))&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; myArray[index] = &lt;span style=&quot;color: blue;&quot;&gt;value&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The &lt;b&gt;Indexer &lt;/b&gt;class can be nested within the &lt;b&gt;GridView &lt;/b&gt;subclass.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The last example shows how to use the custom &lt;b&gt;GridView &lt;/b&gt;on a ASP.NET web page:&lt;br /&gt;
First,&amp;nbsp; use the register tag:&lt;br /&gt;
&lt;b&gt;&amp;lt;%@ Register Namespace=&quot;Eric.TotalGrid&quot; TagPrefix=&quot;x&quot; Assembly=&quot;TotalGrid&quot; %&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Then, use it just like any other &lt;b&gt;GridView&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;lt;x:GridView runat=&quot;server&quot; ....&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;FirstComputedColumnIndex=&quot;4&quot; FirstVisbleComputedColumnIndex=&quot;3&quot; NumberOfComputedColumns=&quot;10&quot;&amp;nbsp; &amp;gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5656374049706903755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/11/gridview-class-with-dynamic-totals.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5656374049706903755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5656374049706903755'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/11/gridview-class-with-dynamic-totals.html' title='ASP.NET GridView Subclass with Dynamic Footer Totals'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-1424672105655610801</id><published>2010-10-28T08:12:00.000-07:00</published><updated>2012-06-12T10:01:17.086-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Controls"/><title type='text'>Set DataRow Values and Other ASP.NET GridView Tips</title><content type='html'>You can set &lt;b&gt;DataRow &lt;/b&gt;values in two ways:&lt;br /&gt;
First, using a column name:&lt;br /&gt;
&lt;i&gt;myDataRow[&quot;City&quot;]= &quot;London&quot;;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Or, using an index:&lt;br /&gt;
&lt;i&gt;myDataRow[2] = &quot;London&quot;;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Don&#39;t use &lt;i&gt;ItemArray &lt;/i&gt;property to set values, it won&#39;t work.&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;color: blue;&quot;&gt;
Set Text Box Width in a GridView Bound Field:&lt;/h4&gt;
Use &lt;b&gt;ControlStyle &lt;/b&gt;properties:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;asp:BoundField... ControlStyle-Width=&quot;60px&quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
&lt;b&gt;Change GridViewRow Appearance:&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
There are different ways to change &lt;b&gt;GridViewRow &lt;/b&gt;appearance. The &lt;a href=&quot;http://blog.devexperience.net/en/5/Change_background_color_of_GridView%27s_Rows.aspx&quot;&gt;approach &lt;/a&gt;I like involves using the GridViewRow &lt;b&gt;Style &lt;/b&gt;property. On &lt;b&gt;RowDataBound &lt;/b&gt;event use this:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; (e.Row.RowType == &lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataControlRowType&lt;/span&gt;.Footer)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; e.Row.Style.Add(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;color&quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;#999999&quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; e.Row.Style.Add(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;font-weight&quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;bold&quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;);&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; ... &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Did you know that you could pass&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;b style=&quot;color: blue;&quot;&gt;data format string &lt;/b&gt;as a parameter to the ToString() method?&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;e.Row.Cells[1].Text = iTotal.ToString(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;F2&quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
The above format string &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx&quot;&gt;specifies &lt;/a&gt;2 decimal places in a numeric value.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/1424672105655610801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/10/set-datarow-values.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/1424672105655610801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/1424672105655610801'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/10/set-datarow-values.html' title='Set DataRow Values and Other ASP.NET GridView Tips'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-8405762202992477336</id><published>2010-10-26T09:30:00.000-07:00</published><updated>2012-06-12T10:01:36.305-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>Simple Linq to Object example without Casting</title><content type='html'>I found this discussion related to casting the result of a &lt;b&gt;LINQ &lt;/b&gt;query to a static object at &lt;a href=&quot;http://devlicio.us/blogs/derik_whittaker/archive/2008/02/22/simple-linq-to-object-example-with-casting.aspx&quot;&gt;http://devlicio.us/blogs/derik_whittaker/archive/2008/02/22/simple-linq-to-object-example-with-casting.aspx&lt;/a&gt; Since it was not possible to post a comment I decided to write a blog entry on my blog.&lt;br /&gt;
&lt;br /&gt;
The example given at the above page gives the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; &amp;gt;&lt;span style=&quot;color: #2b91af;&quot;&gt; &lt;/span&gt;sports = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt; &amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt;&amp;gt;();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sports.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; { SportID = 1, Name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 1&quot;&lt;/span&gt;, Description = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport Desc 1&quot;&lt;/span&gt; });&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sports.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; { SportID = 2, Name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 2&quot;&lt;/span&gt;, Description = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport Desc 2&quot;&lt;/span&gt; });&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sports.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; { SportID = 3, Name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 3&quot;&lt;/span&gt;, Description = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport Desc 3&quot;&lt;/span&gt; });&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sports.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; { SportID = 4, Name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 4&quot;&lt;/span&gt;, Description = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport Desc 4&quot;&lt;/span&gt; });&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
sports.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; { SportID = 5, Name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 5&quot;&lt;/span&gt;, Description = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport Desc 5&quot;&lt;/span&gt; });&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; query = &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; s &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; sports&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/span&gt; s.Name == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 2&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;select&lt;/span&gt; s;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; sport = (&lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt;)query.First();&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
I would like to note that you could rewrite the above statements using lambdas:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;Sport&lt;/span&gt; sport = sports.Where(s =&amp;gt; s.Name == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sport 2&quot;&lt;/span&gt;).First();&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
No &quot;casting&quot; is required.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/8405762202992477336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/10/simple-linq-to-object-example-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8405762202992477336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/8405762202992477336'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/10/simple-linq-to-object-example-with.html' title='Simple Linq to Object example without Casting'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-2496567023082188757</id><published>2010-08-03T08:06:00.000-07:00</published><updated>2014-02-27T13:16:27.644-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="WinForm"/><title type='text'>Resize WinForm Controls Automatically</title><content type='html'>Let&#39; say you have a form with a &lt;b&gt;ListBox &lt;/b&gt;and OK and Cancel buttons.&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKJXB6w3O9Fd1PmsreNpm0S6cWUiRdSqVv1u7TD2WHiM6ux2Whv7g4UDM0fcIgxmwrWqMy1OPJUH5SYVVcuYrnuPJRF12KrGwH__jOs0BSbD-tD4fxLerY75E_ICYlhp_SCHnvaEfYDRU/s1600/form_before.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKJXB6w3O9Fd1PmsreNpm0S6cWUiRdSqVv1u7TD2WHiM6ux2Whv7g4UDM0fcIgxmwrWqMy1OPJUH5SYVVcuYrnuPJRF12KrGwH__jOs0BSbD-tD4fxLerY75E_ICYlhp_SCHnvaEfYDRU/s320/form_before.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a class=&quot;cssButton&quot; href=&quot;javascript:void(0)&quot; id=&quot;previewButton&quot; target=&quot;&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You want controls to be resized automatically when a form is resized. This is how you can achieve this by using the &lt;b&gt;Anchor&lt;/b&gt; property:&lt;br /&gt;
&lt;br /&gt;
Place all controls inside a &lt;b&gt;GroupBox&lt;/b&gt;. Set the &lt;b&gt;Anchor &lt;/b&gt;and &lt;b&gt;Dock &lt;/b&gt;properties&lt;br /&gt;
&lt;br /&gt;
GroupBox properties:&lt;br /&gt;
&lt;b&gt;Anchor&lt;/b&gt; : Top, Bottom, Left, Right&lt;br /&gt;
&lt;b&gt;Dock&lt;/b&gt; : None&lt;br /&gt;
&lt;br /&gt;
Buttons properties:&lt;br /&gt;
&lt;b&gt;Anchor&lt;/b&gt; : Bottom, Right&lt;br /&gt;
&lt;b&gt;Dock &lt;/b&gt;: None&lt;br /&gt;
&lt;br /&gt;
ListBox properties:&lt;br /&gt;
&lt;b&gt;Anchor&lt;/b&gt; : Top, Bottom, Left, Right&lt;br /&gt;
&lt;b&gt;Dock &lt;/b&gt;: None</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/2496567023082188757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/08/resize-controls-automatically.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/2496567023082188757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/2496567023082188757'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/08/resize-controls-automatically.html' title='Resize WinForm Controls Automatically'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKJXB6w3O9Fd1PmsreNpm0S6cWUiRdSqVv1u7TD2WHiM6ux2Whv7g4UDM0fcIgxmwrWqMy1OPJUH5SYVVcuYrnuPJRF12KrGwH__jOs0BSbD-tD4fxLerY75E_ICYlhp_SCHnvaEfYDRU/s72-c/form_before.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-4615619726139560931</id><published>2010-08-03T07:33:00.000-07:00</published><updated>2012-06-12T10:03:02.000-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Registry"/><title type='text'>Save Window Position in Registry</title><content type='html'>This is how you could save a Window position in the Registry so that the Window position could be restored next time the Form loads.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Declare the following constant strings:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; REGKEY = @&quot;SOFTWARE\MyCompany\MyApp\&quot;;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; WINWIDTH = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;windowWidth&quot;&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; WINHEIGHT = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;windowHeight&quot;&lt;/span&gt;;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Then, create a key for your application in the Registry.&amp;nbsp; &lt;br /&gt;
Declare a RegistryKey variable:&lt;br /&gt;
private &lt;span style=&quot;color: #2b91af;&quot;&gt;RegistryKey&lt;/span&gt; key;&lt;br /&gt;
&lt;br /&gt;
Use the following method to obtain the key: &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;RegistryKey&lt;/span&gt; GetKey(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; RegKey)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;RegistryKey&lt;/span&gt; Key = &lt;span style=&quot;color: #2b91af;&quot;&gt;Registry&lt;/span&gt;.CurrentUser.OpenSubKey(RegKey, &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (Key == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Key = &lt;span style=&quot;color: #2b91af;&quot;&gt;Registry&lt;/span&gt;.CurrentUser.CreateSubKey(RegKey);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Key;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
key =&amp;nbsp; GetKey(REGKEY);&lt;br /&gt;
&lt;br /&gt;
Get window width and height:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; width = Form1.Size.Width;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; height = Form1.Size.Height;&lt;/div&gt;
&lt;/div&gt;
Save window width and height in the registry and close the RegistryKey.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
key.SetValue(&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;/span&gt;WINWIDTH, width);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
key.SetValue(&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;/span&gt;WINHEIGHT, height);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
key.Close();&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
When you load your form, read the values from the registry:&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;width = Convert&lt;/span&gt;.ToInt16 (key.GetValue(WINWIDTH));&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;height = Convert&lt;/span&gt;.ToInt16 (key.GetValue(WINHEIGHT));&lt;/div&gt;
&lt;br /&gt;
Set the new window size:&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
Form1.Size = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Size&lt;/span&gt;(width, height);&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/4615619726139560931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/08/save-window-position-in-registry.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/4615619726139560931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/4615619726139560931'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/08/save-window-position-in-registry.html' title='Save Window Position in Registry'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-5329060971553014685</id><published>2010-07-20T13:31:00.000-07:00</published><updated>2012-06-12T10:22:56.177-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="WinForm"/><title type='text'>Concise Code to Enable/Disable WinForm Controls</title><content type='html'>Let&#39;s say you have a check box (cb1)&amp;nbsp; on a form that enables a text box (txt1)&amp;nbsp; and disables a listbox (lst1).&amp;nbsp; You can write a statement that shows this dependency on 2 lines:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;txt1.Enabled = cb1.Checked;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
&amp;nbsp; lst1.Enabled = !cb1.Checked;&lt;/div&gt;
&lt;br /&gt;
This works fine. However, we repeat the reference to the check box state twice.&lt;br /&gt;
There is a way to write the above statements on the same line:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;lst1.Enabled = !(txt1.Enabled = cb1.Checked);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Looks simple when you get it right. But it took me a few minutes to figure it out.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/5329060971553014685/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/concise-code-to-enabledisable-winform.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5329060971553014685'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/5329060971553014685'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/concise-code-to-enabledisable-winform.html' title='Concise Code to Enable/Disable WinForm Controls'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-6029175627267415852</id><published>2010-07-16T13:30:00.000-07:00</published><updated>2012-06-12T10:20:48.669-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Examine Columns in ASP.NET Dynamic Data MetaTable</title><content type='html'>This is how you get access to all columns in a &lt;b&gt;MetaTable &lt;/b&gt;that serves as a data source to your controls like a &lt;b&gt;DetailsView &lt;/b&gt;or a &lt;b&gt;GridView&lt;/b&gt;. &lt;b&gt;Dynamic Data&lt;/b&gt; generates the following code for each &lt;b&gt;ASP.NET&lt;/b&gt; page by default:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MetaTable&lt;/span&gt; table;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Page_Load(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;EventArgs&lt;/span&gt; e)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table = DetailsDataSource.GetTable();&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Title = table.DisplayName; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
The &lt;b&gt;MetaTable &lt;/b&gt;class has a &lt;b&gt;Columns &lt;/b&gt;property that returns a collection of &lt;b&gt;MetaColumns &lt;/b&gt;for the table. This allows us to enumerate through the collection and check for any custom attributes on table columns:&lt;br /&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp; foreach&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;MetaColumn&lt;/span&gt; column &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; table.Columns) &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;div style=&quot;background: white; color: black; font-family: Consolas; font-size: 11pt;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt; (column.Attributes.OfType&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;MyCustomAttribute&lt;/span&gt;&amp;gt;().Count() &amp;gt; 0)&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ......&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; } &lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
This is based on a tip found at &lt;a href=&quot;http://weblogs.asp.net/andrewrea/archive/2009/03/25/asp-net-dynamic-data-using-column-generators-based-on-meta-data.aspx&quot;&gt;this &lt;/a&gt;blog.</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/6029175627267415852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/examine-columns-in-metatable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/6029175627267415852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/6029175627267415852'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/examine-columns-in-metatable.html' title='Examine Columns in ASP.NET Dynamic Data MetaTable'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6212515559541223786.post-3179881680343172469</id><published>2010-07-08T10:39:00.000-07:00</published><updated>2012-02-14T08:26:51.839-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Collections"/><title type='text'>Reverse .NET SortedList</title><content type='html'>&lt;div style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;This post shows how you could reverse a &lt;b&gt;SortedList &lt;/b&gt;in C# by its keys:&lt;/div&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;SortedList&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; strlist = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SortedList&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;strlist.Add(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;f3&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;xxx&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;strlist.Add(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;f1&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ccc&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;strlist.Add(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;f2&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;aaa&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; kvp &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; strlist)&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Key = {0}, Value = {1}&quot;&lt;/span&gt;, kvp.Key, kvp.Value);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;reverse the list&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;&amp;gt; revList = strlist.Reverse();&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; kvp &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; revList)&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Key = {0}, Value = {1}&quot;&lt;/span&gt;, kvp.Key, kvp.Value);&lt;/div&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;}&lt;/div&gt;&lt;br /&gt;
&lt;div style=&#39;float:left; margin-right:4px;&#39;&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://c-sharpe.blogspot.com/feeds/3179881680343172469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/reverse-sortedlist.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3179881680343172469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6212515559541223786/posts/default/3179881680343172469'/><link rel='alternate' type='text/html' href='http://c-sharpe.blogspot.com/2010/07/reverse-sortedlist.html' title='Reverse .NET SortedList'/><author><name>Erik K.</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>