<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
  <channel>
    <title>Evonet Consulting</title>
    <description>ASP.NET Development Blog</description>
    <link>http://blog.evonet.com.au/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.4.5.0</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://blog.evonet.com.au/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Bartek Marnane</dc:creator>
    <dc:title>Evonet Consulting</dc:title>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Evonet" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Using Active Directory to authenticate users to your ASP.NET Web Site.</title>
      <description>&lt;p&gt;ASP.NET membership provides the ability to authenticate users to your web application using forms based authentication against a database of users or directory services.&amp;#160; This article explains the steps required to provide authentication against Active Directory, either for new sites with no authentication, or for existing sites using database authentication.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1 – Set up the Active Directory connection string&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The Active Directory connection string is simliar to the database connection string used in ASP.NET, except that it references an LDAP address.&amp;#160; The connection string is specified in the web.config file.&lt;/p&gt;  &lt;p&gt;The following string will authenticate users in the entire company.com.au tree:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ADConnectionString&amp;quot;&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;connectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LDAP://company.com.au/DC=company,DC=com,DC=au&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you want to restrict authentication to a particular OU, then you specify it in the connection string like so:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ADConnectionString&amp;quot;&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;connectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LDAP://dept.company.com.au/CN=dept,DC=company,DC=com,DC=au&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 – Configure the Membership provider&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your web.config file, create or change the following entry to configure the Membership provider for Active Directory within the &amp;lt;system.web&amp;gt; section:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;#160;&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;membership&lt;/span&gt; &lt;span style="color: #ff0000"&gt;defaultProvider&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyADMembershipProvider&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;providers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyADMembershipProvider&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.Web.Security.ActiveDirectoryMembershipProvider, 
        System.Web, Version=2.0.0.0, Culture=neutral, 
        PublicKeyToken=b03f5f7f11d50a3a&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;connectionStringName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ADConnectionString&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;attributeMapUsername&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;sAMAccountName&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;providers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;membership&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The connectionStringName attribute should match the name of the connection string you created in Step 1.&amp;#160; &lt;/p&gt;

&lt;p&gt;You can configure the credentials used to access Active Directory using the &lt;b&gt;connectionUserName&lt;/b&gt; and &lt;b&gt;connectionPassword&lt;/b&gt; attributes.&amp;#160; If you leave these blank then your application's process identity is used to access Active Directory, regardless of whether your application uses impersonation. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 – Configure the Authentication and Authorization parameters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your web.config file, create or change the following entry to configure the authentication and authorization parameters for Active Directory within the &amp;lt;system.web&amp;gt; section:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;authentication&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Forms&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;forms&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;.ADAuthCookie&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;timeout&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;43200&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;authentication&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;authorization&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;deny&lt;/span&gt; &lt;span style="color: #ff0000"&gt;users&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;?&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;allow&lt;/span&gt; &lt;span style="color: #ff0000"&gt;users&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;authorization&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The authorization settings above require every user to authenticate before accessing your web application.&amp;#160; ASP.NET will automatically redirect these users to a Login.aspx page.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 – Create a Login page&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The simplest way of creating the login page (which must be called Login.aspx) is by using the ASP.NET Login control as the following example demonstrates:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Login&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Login1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Username&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TextMode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;RememberMe&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;btnLogin&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CommandName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Login&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Login&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblLoginErrorDetails&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you are using the Login control, you MUST name your user name and password text boxes exactly as shown in the example.&lt;/p&gt;

&lt;p&gt;The Login control can also provide error checking through the built in LoginError subroutine:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Login1_LoginError(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, 
    &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Login1.LoginError
&lt;span style="color: #0000ff"&gt;If&lt;/span&gt; Login1.UserName = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty &lt;span style="color: #0000ff"&gt;And&lt;/span&gt; Login1.Password = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
    lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Please enter your username and password.&amp;quot;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; Login1.UserName = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
    lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Please enter your username.&amp;quot;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; Login1.Password = &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;.Empty &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
    lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Please enter your password.&amp;quot;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; userInfo &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; MembershipUser = Membership.GetUser(Login1.UserName)
    LoginError.Visible = &lt;span style="color: #006080"&gt;&amp;quot;True&amp;quot;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; userInfo &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;There is no user in the database 
            with the username &amp;quot;&lt;/span&gt; &amp;amp; Login1.UserName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;. Please try again.&amp;quot;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; userInfo.IsApproved &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Your account has not yet been 
                approved. Please try again later.&amp;quot;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; userInfo.IsLockedOut &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Your account has been locked 
                out due to maximum incorrect login attempts. Please 
                contact the site administrator.&amp;quot;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
            lblLoginErrorDetails.Text = &lt;span style="color: #006080"&gt;&amp;quot;Your password is incorrect, 
                please try again.&amp;quot;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;That’s all you should need to allow your users to log on.&amp;#160; This is just the beginning of using Active Directory authentication for your web site, stay tuned for further articles in this series!&lt;/p&gt;

&lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/XoVBasjs5Bo" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/11/05/Using-Active-Directory-to-authenticate-users-to-your-ASPNET-Web-Site.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/11/05/Using-Active-Directory-to-authenticate-users-to-your-ASPNET-Web-Site.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=f69402e7-d26d-4384-94bf-2f419371170b</guid>
      <pubDate>Wed, 05 Nov 2008 15:55:15 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Active Directory</category>
      <category>Authentication</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=f69402e7-d26d-4384-94bf-2f419371170b</pingback:target>
      <slash:comments>6</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=f69402e7-d26d-4384-94bf-2f419371170b</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/11/05/Using-Active-Directory-to-authenticate-users-to-your-ASPNET-Web-Site.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=f69402e7-d26d-4384-94bf-2f419371170b</wfw:commentRss>
    </item>
    <item>
      <title>Creating a Content Management System for your ASP.NET Web Site</title>
      <description>&lt;p&gt;When developing web sites for clients, a simple yet powerful value added proposition is to allow your customers the ability to easily change text on their web site, such as updating contact details, news items, or promotions.&amp;nbsp; &lt;/p&gt; &lt;p&gt;This article will show you how to integrate the popular &lt;a title="http://www.fckeditor.net/" href="http://www.fckeditor.net/"&gt;FCKeditor&lt;/a&gt; HTML Text editor into an ASP.NET site to provide your users with the ability to edit their web site without them having to access the underlying HTML or source files.&lt;/p&gt; &lt;p&gt;The Content Management System (CMS) we will be designing in this tutorial works by storing your page HTML in a database and then using a Formview to bind the HTML to the FCKeditor text control, just like using a normal text box.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 1: Create the Database&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;For this example I will be setting up a simple SQL Server database which holds the HTML content for the pages that the customer will be editing.&lt;/p&gt; &lt;p&gt;I've created a simple table, T_Pages which has 2 columns, one to store the page name, and the other to store the HTML.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="66" alt="Figure 1 - Database Table Design" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaContentManagementSys.NETWebSite_12883/image_3.png" width="345" border="0"&gt; &lt;/p&gt; &lt;p&gt;The PageName field stores the name of the aspx file that we are editing, and the HTML field stores the raw HTML which makes up the page:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="68" alt="Figure 2 - Database Table entries" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaContentManagementSys.NETWebSite_12883/image_8.png" width="476" border="0"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 2: Set up FCKeditor&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Download the latest full version of FCKeditor from &lt;a title="http://www.fckeditor.net/download" href="http://www.fckeditor.net/download"&gt;http://www.fckeditor.net/download&lt;/a&gt;.&amp;nbsp; Extract the files to a directory called &lt;strong&gt;fckeditor&lt;/strong&gt; in the root of your web site.&lt;/p&gt; &lt;p&gt;Download the FCKeditor ASP.NET Control from &lt;a title="http://www.fckeditor.net/download" href="http://www.fckeditor.net/download"&gt;http://www.fckeditor.net/download&lt;/a&gt;.&amp;nbsp; Extract &lt;strong&gt;FredCK.FCKeditorV2.dll &lt;/strong&gt;from the &lt;b&gt;bin/Release/2.0/&lt;/b&gt; folder and place it in the /bin directory in your web site.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="431" alt="Figure 3 - FCKeditor Directory Structure" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaContentManagementSys.NETWebSite_12883/image_11.png" width="246" border="0"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 3: Create a site administration page to edit page content&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Now we create a simple aspx page that contains a Formview.&amp;nbsp; Make sure you secure this page so anonymous users cannot edit the page text!&lt;/p&gt; &lt;p&gt;At the top of the page, register the FCKeditor control:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;%@ Register 
    &lt;span style="color: #0000ff"&gt;Assembly&lt;/span&gt;=&lt;span style="color: #006080"&gt;"FredCK.FCKeditorV2"&lt;/span&gt; 
    &lt;span style="color: #0000ff"&gt;Namespace&lt;/span&gt;=&lt;span style="color: #006080"&gt;"FredCK.FCKeditorV2"&lt;/span&gt; 
    TagPrefix=&lt;span style="color: #006080"&gt;"FCKeditorV2"&lt;/span&gt; %&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now create a Formview with an EditItemTemplate which binds the FCKeditor control to the HTML field in your database depending on what page is to be edited.&amp;nbsp; The FCKeditor control has a large number of settings (see &lt;a title="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide" href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide"&gt;http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide&lt;/a&gt;) but the main ones that we are interested in are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ToolbarSet &lt;/strong&gt;- This allows you to create a custom toolbar that only shows the font manipulation controls that you want your customers to access (We will be discussing this item and customising it further below, under Step 5 - Customising FCKEditor.) 
&lt;li&gt;&lt;strong&gt;EditorAreaCSS&lt;/strong&gt; - This allows you to specify what the text inside the FCKeditor control looks like.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The Formview will also need a Save Button which runs the &lt;strong&gt;update &lt;/strong&gt;command to save changes. I also recommend a Cancel button, but have left it out of this example.&lt;/p&gt;
&lt;p&gt;The Formview code then looks something like this:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:FormView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsSiteAdministration"&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="FormView1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DefaultMode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Edit"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;EditItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;FCKeditorV2:FCKeditor&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="FCKeditor1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;ToolbarSet&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="MyToolbarSet"&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind("html") %&amp;gt;'&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EditorAreaCSS&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="/css/editor.css"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;FCKeditorV2:FCKeditor&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:LinkButton&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="btnSave"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CommandName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Update"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Save changes"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;EditItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:FormView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You also need to create the DataSource.&amp;nbsp; I use the SQLDataSource here, but recommend ObjectDataSources for production environments:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsSiteAdministration"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="&amp;lt;%$ ConnectionStrings:MyConnectionString %&amp;gt;"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="SELECT * FROM [T_Pages] WHERE page=@page"&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;UpdateCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="UPDATE [T_Pages] SET HTML=@HTML WHERE page=@page"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SelectParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:QueryStringParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;QueryStringField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="string"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SelectParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UpdateParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="html"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="string"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:QueryStringParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;QueryStringField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="string"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UpdateParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Our application will call the&lt;strong&gt; SiteAdministration.aspx&lt;/strong&gt; page with a parameter telling it which page to retrieve from the database for editing. such as &lt;strong&gt;SiteAdministration.aspx?page=AboutUs&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You should put checks in your page to ensure that a valid &lt;strong&gt;QueryStringParameter&lt;/strong&gt; is being passed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 4: Modify your pages so they retrieve content from your database&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For existing pages that you wish to allow editing on, simply create a new row in your T_Pages database table with the PageName column containing the page name, and the html column containing all the editable part of the page text, including all html content.&lt;/p&gt;
&lt;p&gt;Then, simply modify your pages by putting in a repeater to display the HTML from your database:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Title&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Repeater&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Repeater1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsPage"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="lblPage"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Eval("HTML") %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Repeater&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The Datasource simply looks at what page you specify (using the DefaultValue setting in the &amp;lt;Parameter&amp;gt; section) and retrieves the appropriate HTML:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsPage"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="&amp;lt;%$ ConnectionStrings:MyConnectionString %&amp;gt;"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="SELECT * FROM [T_Pages] WHERE page=@page"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SelectParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="page"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="string"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DefaultValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="AboutUs"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SelectParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We will also show a link to edit the page.&amp;nbsp; For production environments, you should set this link up to only appear if the user has authenticated as a site administrator.&amp;nbsp; The script below removes the '.aspx'&amp;nbsp; extension from the current page and then creates a hyperlink with the remainder as a query parameter to the Site Administration page.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;If&lt;/span&gt; HttpContext.Current.User.Identity.IsAuthenticated &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; MyPage &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = 
        LCase(Left(System.IO.Path.GetFileName(Request.ServerVariables(&lt;span style="color: #006080"&gt;"SCRIPT_NAME"&lt;/span&gt;)),
        InStr(System.IO.Path.GetFileName(Request.ServerVariables(&lt;span style="color: #006080"&gt;"SCRIPT_NAME"&lt;/span&gt;)), &lt;span style="color: #006080"&gt;"."&lt;/span&gt;) - 1))
    Response.Write(&lt;span style="color: #006080"&gt;"&amp;lt;a href='/admin/siteadministration.aspx?page="&lt;/span&gt; + MyPage + &lt;span style="color: #006080"&gt;"'&amp;gt;Edit this page&amp;lt;/a&amp;gt;"&lt;/span&gt;)
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; If&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So let's recap with an example 'About Us' page called aboutus.aspx:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The SQL Database contains a record for 'aboutus' as the &lt;strong&gt;Page &lt;/strong&gt;and the formatted HTML for the page in the &lt;strong&gt;HTML &lt;/strong&gt;column. 
&lt;li&gt;Visitors to aboutus.aspx will get the formatted HTML page from the database via a Repeater control. 
&lt;li&gt;Site Administrators will see a 'Edit this Page' link which will go to &lt;strong&gt;siteadministration.aspx?page=aboutus.&lt;/strong&gt; 
&lt;li&gt;Clicking on 'Edit this Page' will show the FCKeditor text box populated with the HTML from the database in a WYSIWYG format.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 5: Customising the FCKeditor Toolbar&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To finish off the &lt;strong&gt;ToolbarSet&lt;/strong&gt; can be customised to show only the text manipulation features you approve.&amp;nbsp; The default toolbar set is defined in the \fckeditor\fckconfig.js file as follows:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;FCKConfig.ToolbarSets[&lt;span style="color: #006080"&gt;"Default"&lt;/span&gt;] = [
    [&lt;span style="color: #006080"&gt;'Source'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'DocProps'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Save'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'NewPage'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Preview'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Templates'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'Cut'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Copy'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Paste'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'PasteText'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'PasteWord'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Print'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'SpellCheck'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'Undo'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Redo'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Find'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Replace'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'SelectAll'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'RemoveFormat'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'Form'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Checkbox'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Radio'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'TextField'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Textarea'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Select'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Button'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'ImageButton'&lt;/span&gt;],
    &lt;span style="color: #006080"&gt;'/'&lt;/span&gt;,
    [&lt;span style="color: #006080"&gt;'Bold'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Italic'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Underline'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'StrikeThrough'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Subscript'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Superscript'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'OrderedList'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'UnorderedList'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Outdent'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Indent'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Blockquote'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'JustifyLeft'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'JustifyCenter'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'JustifyRight'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'JustifyFull'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'Link'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Unlink'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Anchor'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'Image'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Flash'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Table'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Rule'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Smiley'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'SpecialChar'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'PageBreak'&lt;/span&gt;],
    &lt;span style="color: #006080"&gt;'/'&lt;/span&gt;,
    [&lt;span style="color: #006080"&gt;'Style'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'FontFormat'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'FontName'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'FontSize'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'TextColor'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'BGColor'&lt;/span&gt;],
    [&lt;span style="color: #006080"&gt;'FitWindow'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'ShowBlocks'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'About'&lt;/span&gt;]        &lt;span style="color: #008000"&gt;// No comma for the last row.&lt;/span&gt;
] ;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;which shows:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="center"&gt;&amp;nbsp;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="83" alt="Figure 4 - Default Toolbar" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaContentManagementSys.NETWebSite_12883/image_13.png" width="768" border="0"&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You may wish to cut down some of these options by defining your own toolbar set.&amp;nbsp; For example:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;FCKConfig.ToolbarSets[&lt;span style="color: #006080"&gt;"Mytoolbarset"&lt;/span&gt;] = [
    [&lt;span style="color: #006080"&gt;'Bold'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Italic'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'OrderedList'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'UnorderedList'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'-'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Link'&lt;/span&gt;,&lt;span style="color: #006080"&gt;'Unlink'&lt;/span&gt;]
] ;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="33" alt="Figure 4 - MyToolbarset" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaContentManagementSys.NETWebSite_12883/image_16.png" width="167" border="0"&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You need to reference your new ToolbarSet in your ASP.NET control, as discussed in Step 3.&lt;/p&gt;
&lt;p&gt;That's it!&amp;nbsp; There are many more options to play around with, and the whole source code is available to customise even futher.&amp;nbsp; For more details, check out the &lt;a title="http://www.fckeditor.net/" href="http://www.fckeditor.net/"&gt;FCKeditor&lt;/a&gt; web site.&lt;/p&gt;
&lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/9hw5JFtjctA" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/09/01/Creating-a-Content-Management-System-for-your-ASPNET-Web-Site.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/09/01/Creating-a-Content-Management-System-for-your-ASPNET-Web-Site.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=c16f646d-22f6-4bc3-913d-e57a20b1a70a</guid>
      <pubDate>Mon, 01 Sep 2008 00:46:41 +1100</pubDate>
      <category>ASP.NET</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=c16f646d-22f6-4bc3-913d-e57a20b1a70a</pingback:target>
      <slash:comments>19</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=c16f646d-22f6-4bc3-913d-e57a20b1a70a</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/09/01/Creating-a-Content-Management-System-for-your-ASPNET-Web-Site.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=c16f646d-22f6-4bc3-913d-e57a20b1a70a</wfw:commentRss>
    </item>
    <item>
      <title>Setting up SQL Server 2008 for an ASP.NET website on IIS 7.0</title>
      <description>&lt;p&gt;SQL Server 2008 Express edition with Tools has finally been released (It was launched on August 11th, but only today are the management tools available).&amp;nbsp; As I've been building web servers today, I've put together this comprehensive guide to setting up your website to work with SQL Server 2008.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 1: Prerequisities&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;Firstly you need Windows 2008 Server and IIS 7.0 installed. Installing Windows Server 2008 is pretty straight-forward and I won't cover it here (there is an excellent article &lt;a href="http://www.petri.co.il/how-to-install-windows-server-2008-step-by-step.htm"&gt;here&lt;/a&gt;), although be aware that as you are using ASP.NET and SQL Server you cannot install server core.&amp;nbsp; Installing the IIS 7.0 server role is also quite easy, (another great article &lt;a href="http://learn.iis.net/page.aspx/29/installing-iis7-on-windows-server-2008/"&gt;here&lt;/a&gt;) &lt;/p&gt; &lt;li&gt; &lt;p&gt;Install Windows PowerShell from the Features section in the Windows Server 2008 Server Manager. &lt;/p&gt; &lt;li&gt; &lt;p&gt;Install .NET Framework 3.5 SP1 from &lt;a title="http://www.microsoft.com/net/" href="http://www.microsoft.com/net/"&gt;here&lt;/a&gt;. &lt;/p&gt; &lt;li&gt; &lt;p&gt;Install Windows Installer 4.5 from &lt;a title="http://www.microsoft.com/downloads/details.aspx?FamilyId=5A58B56F-60B6-4412-95B9-54D056D6F9F4&amp;amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5A58B56F-60B6-4412-95B9-54D056D6F9F4&amp;amp;displaylang=en"&gt;here&lt;/a&gt;. &lt;/p&gt; &lt;li&gt; &lt;p&gt;If you have AJAX enabled sites running on ASP.NET 2.0 then Install ASP.NET AJAX Extensions 1.0 from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&amp;amp;displaylang=en"&gt;here&lt;/a&gt;. &lt;/p&gt; &lt;li&gt; &lt;p&gt;Download SQL Server 2008 Express with Tools from &lt;a href="http://www.microsoft.com/express/sql/register/default.aspx"&gt;here&lt;/a&gt;.&amp;nbsp; This version includes:&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt; &lt;ul&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;SQL Server database engine - create, store, update and retrieve your data &lt;/p&gt; &lt;li&gt; &lt;p&gt;SQL Server Management Studio Basic - visual database management tool for creating, editing and managing databases&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;blockquote&gt; &lt;p&gt;While this guide concentrates on the Express version of SQL Server 2008, you need to ensure that it meets the requirements in your specific environment.&amp;nbsp; The SQL Server 2008 blog has an article which discusses this issue (&lt;a href="http://blogs.msdn.com/sqlexpress/archive/2008/02/22/sql-server-express-and-hosting.aspx"&gt;SQL Server Express and Hosting&lt;/a&gt;)&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 2: &lt;/strong&gt;&lt;strong&gt;Installing SQL Server 2008&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;Start the install from your CD or downloaded file.&lt;/p&gt; &lt;li&gt; &lt;p&gt;Select &lt;strong&gt;New SQL Server stand-alone installation of add features to an existing installation&lt;/strong&gt;&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 1 - Start Installation" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_1.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;The setup program will check that you have the necessary pre-requisities in place for the SQL Server setup support files.&amp;nbsp; Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 2- Check pre-requisities for setup support files" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_2.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Click &lt;strong&gt;Install &lt;/strong&gt;to install the SQL Server setup support files.&lt;/p&gt; &lt;li&gt; &lt;p&gt;SQL Setup will then check that you have all the necessary pre-requisities in place for the SQL Server installation.&amp;nbsp; I received a warning that Windows Firewall needs port 1433 open for remote TCP/IP connection to SQL Server.&amp;nbsp; Click &lt;strong&gt;Next.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 3 - Check pre-requisities for the SQL Server installation" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_3.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/strong&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Nothing to do on the next step if you are using the Express Edition, other you need to enter a valid product key.&amp;nbsp; Click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Accept the license terms and click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Select the features you want to install and cick &lt;strong&gt;Next&lt;/strong&gt;.&amp;nbsp; At a minimum I recommend installing the &lt;strong&gt;Database Engine Services&lt;/strong&gt; and the &lt;strong&gt;Management Tools.&lt;/strong&gt; &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="185" alt="Figure 4 - Select features" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_4.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Select an instance to install your database server into and a location.&amp;nbsp; In the web.config file for your ASP.NET web site, if SQL is not installed in the default instance then you need to set Data Source = SERVERNAME\INSTANCENAME for your database connection string.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_12.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 5 - Select an instance" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_5.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;SQL Setup will confirm you have enough disk space. Click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Configure your service account and collation settings and click &lt;strong&gt;Next. &lt;/strong&gt;Use the built-in System account and don't change the default collation unless you have databases with special requirements.&lt;/p&gt; &lt;li&gt; &lt;p&gt;Configure &lt;strong&gt;Mixed Mode authentication &lt;/strong&gt;and provide a password for the sa account.&amp;nbsp; This allows you to use either windows or sql authentication depending on your requirements.&amp;nbsp; Choose which accounts have administrative privilages to the SQL Server database engine.&amp;nbsp; Click &lt;strong&gt;Next. &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_14.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 6 - Configure authentication" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_6.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/strong&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Tick the checkboxes if you would like to send error reports and usage data to Microsoft, and click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt; &lt;li&gt; &lt;p&gt;Setup will then check if the installation process will be blocked.&amp;nbsp; Check the report and click &lt;strong&gt;Next. &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_16.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Figure 7" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_7.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt;&lt;/strong&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Verify the SQL Server features to install and click &lt;strong&gt;Install.&amp;nbsp; &lt;/strong&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Once the setup finishes, check Windows Update to see if there are any patches that need to be installed.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 3: &lt;/strong&gt;&lt;strong&gt;Allowing TCP/IP Connections to SQL Server&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;By default, only the Named Pipes protocal is allowed to connect to the SQL Server.&amp;nbsp; To allow TCP/IP connections, perform the following steps:&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;Open the &lt;strong&gt;SQL Server Configuration Manager &lt;/strong&gt;under the &lt;strong&gt;Microsoft SQL Server 2008, Configuration Tools &lt;/strong&gt;start menus.&lt;strong&gt;&amp;nbsp; &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="166" alt="Figure 8 - SQL Server Configuration Manager" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_35.png" width="256" border="0" heigt="166"&gt; &lt;/center&gt;&lt;/strong&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Expand the &lt;strong&gt;SQL Server Network Configuration &lt;/strong&gt;node and select &lt;strong&gt;Protocols for &amp;lt;InstanceName&amp;gt;.&amp;nbsp; &lt;/strong&gt;Double click on the TCP/IP Protocol and change it to &lt;strong&gt;Enabled&lt;/strong&gt;. &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="100" alt="Figure 9 - SQL Server Configuration Manager" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_34.png" width="520" border="0"&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt;Restart SQL Server for the changes to take effect.  &lt;p&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 4: &lt;/strong&gt;&lt;strong&gt;Attaching a Database&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The SQL Server 2008 Management tools are almost identical to the SQL Server 2005 ones.&amp;nbsp; Open up the Management Tools and login to your database.&amp;nbsp; You will then see the following: &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="228" alt="Figure 10 - Attach a database" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_33.png" width="289" border="0"&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt;Right-click on the &lt;strong&gt;Databases&lt;/strong&gt; node and select &lt;strong&gt;New Database &lt;/strong&gt;to create a new database, or &lt;strong&gt;Attach &lt;/strong&gt;to attach an existing one.&amp;nbsp;&amp;nbsp; If you are attaching a database then click the &lt;strong&gt;Add&lt;/strong&gt; button, browse for your .mdf file and click &lt;strong&gt;OK&lt;/strong&gt; twice to attach the database.&amp;nbsp; You will be asked to also add the location of any Full-Text catalogs if they exist.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 5: &lt;/strong&gt;&lt;strong&gt;Creating a Login for your database&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;By default, only Administrators have access to your database.&amp;nbsp; You need to now configure your database to allow Internet users access to read and (if required) write to your data.&amp;nbsp; You can either use Windows authentication or SQL Server authentication.&amp;nbsp; Windows authentication uses your local server or Active Directory user account to connect, and doesn't require a password to be kept in the web.config file.&amp;nbsp; SQL Server authentication is easier to seperate your user accounts for different databases and applications easily.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;To set up Windows Authentication:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;On a standalone Windows 2008 Web Server, the ASP.NET service runs as the NT AUTHORITY\NETWORK SERVICE account.&amp;nbsp; You need to map this account to SQL Server:&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;In the SQL Server Management Tools, Right click on &lt;strong&gt;Logins &lt;/strong&gt;under the &lt;strong&gt;Security Node&lt;/strong&gt; and select &lt;strong&gt;New Login&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="195" alt="Figure 11 - Mapping a Windows Account" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_32.png" width="285" border="0"&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Type &lt;strong&gt;NT AUTHORITY\NETWORK SERVICE &lt;/strong&gt;in the Login Name box and select &lt;strong&gt;Windows Authentication&lt;/strong&gt;.&amp;nbsp; Click &lt;strong&gt;Ok&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_26.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="Figure 12 - New Login" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_12.png" width="211" border="0"&gt;&lt;/a&gt;&lt;/center&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;To set up SQL Authentication:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;In the SQL Server Management Tools, Right click on &lt;strong&gt;Logins &lt;/strong&gt;under the &lt;strong&gt;Security Node&lt;/strong&gt; and select &lt;strong&gt;New Login&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="195" alt="Figure 13 - Mapping a Windows Account" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_32.png" width="285" border="0"&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Type the name of your database user in the Login Name box and select &lt;strong&gt;SQL Authentication&lt;/strong&gt;.&amp;nbsp; Set a password and untick &lt;strong&gt;Enforce Password Policy. &lt;/strong&gt;Click &lt;strong&gt;Ok&lt;/strong&gt;. &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_39.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="Figure 14 - SQL Authentication" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_16.png" width="225" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/center&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 6: &lt;/strong&gt;&lt;strong&gt;Assigning the user permissions to your database&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;Now you need to assign this login the appropriate permissions in your database. To do this, expand the &lt;strong&gt;Databases &lt;/strong&gt;node and then expand &lt;strong&gt;Security&lt;/strong&gt;. Right-click the &lt;strong&gt;Users &lt;/strong&gt;node and choose &lt;strong&gt;New User&lt;/strong&gt;.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="405" alt="Figure 15 - Assign this login the appropriate permissions in your database" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_31.png" width="285" border="0"&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Give your Login whatever name you like and in the Login Name box type in either the name of your database user if using SQL authentication or &lt;strong&gt;NT AUTHORITY\NETWORK SERVICE &lt;/strong&gt;if you are using Windows authentication (or browse to select your account).&amp;nbsp; Under Database Role Membership select db_datareader (and db_datawriter if your users are performing INSERT and UPDATE SQL queries).&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_37.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="237" alt="Figure 16 - Login name and Database Role Membership" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_15.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 7: &lt;/strong&gt;&lt;strong&gt;Configuring your database connection string&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;You can set your database connection string by either manually editing the web.config file, or using the IIS built in &lt;strong&gt;Connection Strings&lt;/strong&gt; applet.&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;Open &lt;strong&gt;Internet Information Services (IIS) Manager &lt;/strong&gt;from the &lt;strong&gt;Administrative Tools &lt;/strong&gt;start menu.&lt;/p&gt; &lt;li&gt; &lt;p&gt;Browse to your website and double-click on &lt;strong&gt;Connection Strings &lt;/strong&gt;in the right hand pane. &lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="166" alt="Figure 17 - Connection Strings" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_42.png" width="756" border="0"&gt; &lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Either &lt;strong&gt;Add &lt;/strong&gt;a new connection string or right click an existing one to &lt;strong&gt;Edit.&lt;/strong&gt;&lt;/p&gt; &lt;li&gt; &lt;p&gt;Set the name of your server and database appropriately, and then choose the credentials to match your database user.&amp;nbsp; If you are using SQL Authentication then you need to set the username and password you configured.&lt;br&gt;&lt;br&gt; &lt;center&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_44.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="201" alt="Figure 18 - Adding a connection string" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Settingupa.NETwebserverwithSQLServer2008_150E3/image_thumb_18.png" width="244" border="0"&gt;&lt;/a&gt;&lt;/center&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;That's it!&amp;nbsp; I hope this guide helps, and please let me know if I've missed anything!&lt;/p&gt; &lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/rdLyt687qCI" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/24/Setting-up-SQL-Server-2008-for-an-ASPNET-website-on-IIS-70.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/24/Setting-up-SQL-Server-2008-for-an-ASPNET-website-on-IIS-70.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=a40894d4-2fc0-4438-a236-1187d43b3253</guid>
      <pubDate>Sun, 24 Aug 2008 16:22:17 +1100</pubDate>
      <category>IIS 7.0</category>
      <category>SQL Server 2008</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=a40894d4-2fc0-4438-a236-1187d43b3253</pingback:target>
      <slash:comments>5</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=a40894d4-2fc0-4438-a236-1187d43b3253</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/24/Setting-up-SQL-Server-2008-for-an-ASPNET-website-on-IIS-70.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=a40894d4-2fc0-4438-a236-1187d43b3253</wfw:commentRss>
    </item>
    <item>
      <title>503 "service unavailable" errors when IIS running in 32-bit mode on 64-bit Windows Server 2008</title>
      <description>&lt;p&gt;Yesterday I managed to take down my development web server.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I changed one of my customer's web sites from an SQL database to Microsoft Access, and as I am running 64 bit Windows Server 2008 and there is no 64-bit OleDB driver for Access, I had to change the Advanced Settings in the site's application pool to enable 32-bit applications:&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="209" alt="" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/2be693c586ce_8A63/image_6.png" width="454" border="0"&gt;&amp;nbsp; &lt;/p&gt; &lt;p&gt;Unfortunately, I then started getting &lt;strong&gt;Service Unavailable Errors: HTTP Error 503. The service is unavailable&lt;/strong&gt; on all the sites on my development box.&amp;nbsp; Changing the above 32-bit setting back to false didn't solve the problem.&lt;/p&gt; &lt;p&gt;Mike Volodarsky on his &lt;a title="IIS 7.0 Server-Side" href="http://mvolo.com/blogs/serverside/default.aspx"&gt;IIS 7.0 Server-Side&lt;/a&gt; blog has a great article describing the problems that I was having &lt;a title="http://mvolo.com/blogs/serverside/archive/2006/10/19/Where-did-my-IIS7-server-go_3F00_-Troubleshooting-_2200_service-unavailable_2200_-errors.aspx" href="http://mvolo.com/blogs/serverside/archive/2006/10/19/Where-did-my-IIS7-server-go_3F00_-Troubleshooting-_2200_service-unavailable_2200_-errors.aspx"&gt;here&lt;/a&gt; and this is the first port of call for anyone having these same issues.&amp;nbsp; My own problem however, ended up being that IIS seemed stuck in 32-bit compatibility mode after I enabled 32-bit application support, which then caused all my IIS worker processes to fail (Not sure why though!)&lt;/p&gt; &lt;p&gt;To resolve the issue, I ended up needing to run the following script in a command prompt:&lt;/p&gt; &lt;p&gt;&lt;b&gt;cscript c:\inetpub\adminscripts\adsutil.vbs SET /w3svc/AppPools/Enable32BitAppOnWin64 False&lt;/b&gt;&lt;/p&gt; &lt;p&gt;After I restarted my application pools, everything worked again.&lt;/p&gt; &lt;p&gt;Hope this helps,&lt;/p&gt; &lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/NqIgf-J7UBY" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/22/503-service-unavailable-errors-when-IIS-running-in-32-bit-mode-on-64-bit-Windows-Server-2008.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/22/503-service-unavailable-errors-when-IIS-running-in-32-bit-mode-on-64-bit-Windows-Server-2008.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=4aeb306b-c4e9-44b5-8e8a-23af33522d10</guid>
      <pubDate>Fri, 22 Aug 2008 10:40:41 +1100</pubDate>
      <category>IIS 7.0</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=4aeb306b-c4e9-44b5-8e8a-23af33522d10</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=4aeb306b-c4e9-44b5-8e8a-23af33522d10</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/22/503-service-unavailable-errors-when-IIS-running-in-32-bit-mode-on-64-bit-Windows-Server-2008.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=4aeb306b-c4e9-44b5-8e8a-23af33522d10</wfw:commentRss>
    </item>
    <item>
      <title>Integrating Google Maps into an ASP.NET page</title>
      <description>&lt;p&gt;While Microsoft have released their &lt;a title="http://dev.live.com/blogs/devlive/archive/2008/07/27/386.aspx" href="http://dev.live.com/blogs/devlive/archive/2008/07/27/386.aspx"&gt;new Virtual Earth ASP.NET Control&lt;/a&gt;, I still haven't found a decent wrapper that converts addresses to langitude and longitude co-ordinates.&amp;nbsp; There is a Geo coder web service available &lt;a href="http://geocoder.us/service/rest/?address=1600%20Pennsylvania%20Avenue%20NW%20Washington,%20DC%2020500"&gt;here (this shows the co-ordinates for the White House)&lt;/a&gt; but it seems to only work for US addresses, which doesn't help me at all.&lt;/p&gt; &lt;p&gt;So for the moment, I'm still using Google Maps, and have prepared the following to show you how to integrate Google Maps into your ASP.NET pages.&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="512" alt="image" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/DisplayingGoogleMapsfor_13A52/image_3.png" width="538" border="0"&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="http://demo.evonet.com.au/GoogleMaps.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/GoogleMaps.rar"&gt;Code&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Step 1.&lt;/b&gt; &lt;strong&gt;Get a Google Maps API key&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;In order to use Google Maps on your site, you need to register for a free Google Maps API key from here: &lt;a href="http://www.google.com/apis/maps/"&gt;http://www.google.com/apis/maps/&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Step 2.&lt;/b&gt; &lt;strong&gt;Download the SubGurim Google Maps wrapper dll&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This one is the best Google Maps wrapper I have found so far &lt;a href="http://en.googlemaps.subgurim.net/descargar.aspx"&gt;http://en.googlemaps.subgurim.net/descargar.aspx&lt;/a&gt;.&amp;nbsp; It is a commercial product (from $10), or you can put up with the overlayed text in the free versions.&lt;/p&gt; &lt;p&gt;Download the gmaps.dll file and add it to your \bin directory.&lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Step 3. Set up your aspx page&lt;/b&gt;&lt;/p&gt; &lt;p&gt;In your aspx page, add a few text boxes to gather the address details.&amp;nbsp; You can simply use one textbox, or split the address to enable validation for suburbs, countries, etc.&amp;nbsp; I haven't included any form validation in my example.&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="text-align:right; margin-right:300px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    Street Address: 
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:textbox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtStreetAddress"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="150px"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    Suburb: 
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:textbox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtSuburb"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="150px"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    Country: 
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:textbox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtCountry"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="150px"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Show Map"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="lnkShowMap"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You need to add your Google API key to your web.config file like so:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="googlemaps.subgurim.net"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="YourGoogleMapsAPIKeyHere"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And finally, you need to register the SubGurim wrapper at the top of your page (or in your web.config if you have a number of pages that display maps): 
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;strong&gt;Step 4: Add code to display the map&lt;/strong&gt; 
&lt;p&gt;Finally, add code that collates your address fields and calls the Google Maps wrapper. 
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; lnkShowMap_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.EventArgs)
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; lnkShowMap.Click
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; strFullAddress &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; sMapKey &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = 
    ConfigurationManager.AppSettings(&lt;span style="color: #006080"&gt;"googlemaps.subgurim.net"&lt;/span&gt;)
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; GeoCode &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Subgurim.Controles.GeoCode

    &lt;span style="color: #008000"&gt;' Combine our address fields to create the full address.  The street, &lt;/span&gt;
    &lt;span style="color: #008000"&gt;' suburb and country should be seperated by  periods (.)&lt;/span&gt;
    strFullAddress = txtStreetAddress.Text &amp;amp; &lt;span style="color: #006080"&gt;". "&lt;/span&gt; &amp;amp; txtSuburb.Text
        &amp;amp; &lt;span style="color: #006080"&gt;". "&lt;/span&gt; &amp;amp; txtCountry.Text

    &lt;span style="color: #008000"&gt;' Work out the longitude and latitude&lt;/span&gt;
    GeoCode = GMap1.geoCodeRequest(strFullAddress, sMapKey)
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; gLatLng &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, 
        GeoCode.Placemark.coordinates.lng)
    &lt;span style="color: #008000"&gt;' Display the map&lt;/span&gt;
    GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal)
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; oMarker &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Subgurim.Controles.GMarker(gLatLng)
    GMap1.addGMarker(oMarker)
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That's it! Check out the &lt;a href="http://demo.evonet.com.au/GoogleMaps.aspx"&gt;demo&lt;/a&gt; or download the &lt;a href="http://demo.evonet.com.au/GoogleMaps.rar"&gt;source code&lt;/a&gt;, and let me know if you find a good wrapper for the Virtual Earth ASP.NET control!&lt;/p&gt;
&lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/0n8_z7JRqpE" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/19/Integrating-Google-Maps-into-an-ASPNET-page.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/19/Integrating-Google-Maps-into-an-ASPNET-page.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=f5c8312c-1f43-4cd6-95b5-acdb5c8a1a1a</guid>
      <pubDate>Tue, 19 Aug 2008 18:08:23 +1100</pubDate>
      <category>ASP.NET</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=f5c8312c-1f43-4cd6-95b5-acdb5c8a1a1a</pingback:target>
      <slash:comments>5</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=f5c8312c-1f43-4cd6-95b5-acdb5c8a1a1a</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/19/Integrating-Google-Maps-into-an-ASPNET-page.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=f5c8312c-1f43-4cd6-95b5-acdb5c8a1a1a</wfw:commentRss>
    </item>
    <item>
      <title>Inserting a new record from the Listview's footer</title>
      <description>&lt;p&gt;The Listview control introduced in ASP.NET 3.5 fixes a number of issues with the old Gridview and Repeater controls.&amp;nbsp; In particular, one of my biggest problems with the Gridview was the inability to add an item through an empty row in the Gridview footer.&amp;nbsp; While there are several workarounds to achieve this functionality, the Listview makes it nice and easy.&amp;nbsp; This article demonstrates how.&lt;/p&gt; &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="253" alt="image" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/InsertingItemsintoaListview_103C5/image_3.png" width="551" border="0"&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="http://demo.evonet.com.au/Listviewwithinsert.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/Listviewwithinsert.rar"&gt;Code&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Step 1 - Create a Listview&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Create a simple listview with a LayoutTemplate and ItemTemplate to display your data.&amp;nbsp; Here is some sample code you can use:&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Listview2"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="ID"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsListView"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;InsertItemPosition&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="LastItem"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellpadding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellspacing&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="ListviewTable"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="540"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 40px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                ID
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 110px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                First Name
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 110px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                Last Name
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 120px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                Department
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 120px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                Location
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="width: 40px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="itemPlaceholder"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;colspan&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="5"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;align&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="center"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                Page:
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DataPager&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="DataPager1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="12"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Fields&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:NumericPagerField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ButtonCount&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="5"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Fields&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DataPager&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval("ID")&lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval("FirstName")&lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval("LastName")&lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval("Location")&lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval("Department")&lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the Listview control you'll see &lt;span style="color: #ff0000"&gt;InsertItemPosition&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="LastItem"&lt;/span&gt; which puts the insert item template into the Listview's footer.&amp;nbsp; You can use FirstItem to show the insert item template at the top of your data.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2 - Create the SQL Data Source&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;My usual disclaimer here - I don't recommend using SQL Data Sources in a production environment, I instead prefer to seperate the data access layer and use Object Data sources.&amp;nbsp; However, for the purposes of this demo, the SQKDataSource is a lot easier to demonstrate.&lt;/p&gt;
&lt;p&gt;Make sure you include an InsertCommand and InsertParameters as shown below:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dsListview"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="&amp;lt;%$ ConnectionStrings:MyConnection %&amp;gt;"&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="SELECT * FROM [T_Employees]"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;InsertCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Insert into T_Employees (firstname, lastname, location, department) 
values (@firstname, @lastname, @location, @department)"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;InsertParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="FirstName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="String"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="LastName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="String"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Location"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="String"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Department"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="String"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;InsertParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3 - Add the InsertItemTemplate&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Finally, add an InsertDataTemplate which contains bound controls for your InsertParameters.&amp;nbsp; I've also included validators here and a validation summary, to ensure that proper data is being entered into the database:&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;InsertItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;&amp;amp;nbsp;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtFirstName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="80px"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%#Bind("FirstName")%&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="RV1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtFirstName"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="First Name is required."&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Dynamic"&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;*&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtLastName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="80px"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%#Bind("LastName")%&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="RV2"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtLastName"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Last Name is required."&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Dynamic"&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;*&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtLocation"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="90px"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%#Bind("Location")%&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="RV3"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtLocation"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Location is required."&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Dynamic"&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;*&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtDepartment"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="90px"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%#Bind("Department")%&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="RV4"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="txtDepartment"&lt;/span&gt;
            &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Department is required."&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Dynamic"&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;*&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:RequiredFieldValidator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:LinkButton&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="LinkButton1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CommandName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Insert"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Add"&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CausesValidation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ValidationSummary&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="ValidationSummary1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ShowMessageBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ShowSummary&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ValidationGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="InsertFields"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;InsertItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That's it!&amp;nbsp; You now have text boxes in your Listview's footer that allow your users to insert items into your database.&amp;nbsp; If you want to make the user press a button to display the Insert Item template, then in your Listview, set &lt;span style="color: #ff0000"&gt;InsertItemPosition&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="None."&lt;/span&gt; Then, create an 'Add' button and in your code behind type 'Listview1.InsertItemPosition = InsertItemPosition.FirstItem'.&amp;nbsp; After the insert you can then set 'Listview1.InsertItemPosition = InsertItemPosition.None' (Put this in your Listview1_ItemInserted Sub).&lt;/p&gt;
&lt;p&gt;As usual, check out the &lt;a href="http://demo.evonet.com.au/Listviewwithinsert.aspx"&gt;demo&lt;/a&gt; or download the &lt;a href="http://demo.evonet.com.au/Listviewwithinsert.rar"&gt;source code&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Good luck,&lt;/p&gt;
&lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/7fDCwZarZgM" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/17/Inserting-a-new-record-from-the-Listviews-footer.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/17/Inserting-a-new-record-from-the-Listviews-footer.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=3427b8c4-7b80-48e1-8992-10f3cae3cc46</guid>
      <pubDate>Sun, 17 Aug 2008 21:09:53 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Listview</category>
      <category>Validation</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=3427b8c4-7b80-48e1-8992-10f3cae3cc46</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=3427b8c4-7b80-48e1-8992-10f3cae3cc46</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/17/Inserting-a-new-record-from-the-Listviews-footer.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=3427b8c4-7b80-48e1-8992-10f3cae3cc46</wfw:commentRss>
    </item>
    <item>
      <title>Visual Studio 2008 Service Pack 1 and .NET Framework 3.5 Service Pack 1 Released</title>
      <description>&lt;p&gt;Full details and download link at &lt;a title="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx" href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx"&gt;http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Visual Studio 2008 SP1 delivers: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Improved WPF designers&lt;/li&gt;    &lt;li&gt;SQL Server 2008 support &lt;/li&gt;    &lt;li&gt;ADO.NET Entity Designer &lt;/li&gt;    &lt;li&gt;Visual Basic and Visual C++ components and tools (including an MFC-based Office 2007 style &amp;#8216;Ribbon&amp;#8217;) &lt;/li&gt;    &lt;li&gt;Visual Studio Team System Team Foundation Server (TFS) addresses customer feedback on version control usability and performance, email integration with work item tracking and full support for hosting on SQL Server 2008 &lt;/li&gt;    &lt;li&gt;Richer JavaScript support, enhanced AJAX and data tools, and Web site deployment improvements&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The .NET Framework 3.5 SP1 delivers:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Performance increases between 20-45% for WPF-based applications &amp;#8211; without having to change any code&lt;/li&gt;    &lt;li&gt;WCF improvements that give developers more control over the way they access data and services &lt;/li&gt;    &lt;li&gt;Streamlined installation experience for client applications &lt;/li&gt;    &lt;li&gt;Improvements in the area of data platform, such as the ADO.NET Entity Framework, ADO.NET Data Services and support for SQL Server 2008&amp;#8217;s new features&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Cheers,&lt;/p&gt;  &lt;p&gt;Bartek&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/Xa71FO2s8xM" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/12/Visual-Studio-2008-Service-Pack-1-and-NET-Framework-35-Service-Pack-1-Released.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/12/Visual-Studio-2008-Service-Pack-1-and-NET-Framework-35-Service-Pack-1-Released.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=6331756c-7255-4e80-893c-95d5ae53c908</guid>
      <pubDate>Tue, 12 Aug 2008 16:10:52 +1100</pubDate>
      <category>ASP.NET</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=6331756c-7255-4e80-893c-95d5ae53c908</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=6331756c-7255-4e80-893c-95d5ae53c908</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/12/Visual-Studio-2008-Service-Pack-1-and-NET-Framework-35-Service-Pack-1-Released.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=6331756c-7255-4e80-893c-95d5ae53c908</wfw:commentRss>
    </item>
    <item>
      <title>Maintaining Checkbox State in a Listview</title>
      <description>&lt;p&gt;I wrote an article recently explaining how to create a &lt;a href="http://blog.evonet.com.au/post/2008/06/Gridview-that-exports-selected-rows-to-Excel.aspx"&gt;Gridview that exports selected rows to Excel&lt;/a&gt;, and have received a number of queries about how to do the same with a Listview.&amp;#160; The Listview, like the Gridview, doesn't automatically remember whether a checkbox is selected or not for each row, unless you store the value immediately in a database after each change, which is inefficient.&lt;/p&gt;  &lt;p&gt;This example shows how to maintain checkbox state across paging and sorting within a Listview.&amp;#160; The final steps in &lt;a href="http://blog.evonet.com.au/post/2008/06/Gridview-that-exports-selected-rows-to-Excel.aspx"&gt;Gridview that exports selected rows to Excel&lt;/a&gt; will show you how to export these rows to Excel if you wish.&lt;/p&gt;  &lt;p align="center"&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="362" alt="Maintaining Checkbox State in a Listview" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/MaintainingCheckboxStateinaListview_B8D3/image_3.png" width="561" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://demo.evonet.com.au/MaintainingListviewCheckboxState.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/MaintainingListviewCheckboxState.rar"&gt;Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1 - Create a Listview&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The ListView control was introduced in ASP.NET 3.5.&amp;#160; It is an enhancement to the DataList and Repeater controls, and works by using templates to determine how records are formatted.&amp;#160; This gives you the flexibility to display mulitple records in a horizontal or vertical grid, or in groups of 3 etc.&amp;#160; For this example. the Listview I create will mimic the data display of a Gridview.&lt;/p&gt;  &lt;p&gt;The basic layout of the Listview control is as follows:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ListView&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        ...
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        ...
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I am using a simple table of four data columns, with a fifth column that will display the checkboxes.&amp;#160; I have also included a DataPager control which handles the Listview's paging.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Listview1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ID&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsListView&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellpadding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellspacing&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ListviewTable&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;540&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 120px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    Fist Name
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 120px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    Last Name
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 120px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    Department
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 120px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    Location
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 60px; text-align: center&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;th&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;itemPlaceholder&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;colspan&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;align&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    Page:
                    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DataPager&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DataPager1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;12&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Fields&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:NumericPagerField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ButtonCount&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Fields&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DataPager&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;LayoutTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval(&amp;quot;FirstName&amp;quot;) &lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval(&amp;quot;LastName&amp;quot;) &lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval(&amp;quot;Department&amp;quot;) &lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="background-color: #ffff00"&gt;&amp;lt;%&lt;/span&gt;#Eval(&amp;quot;Location&amp;quot;) &lt;span style="background-color: #ffff00"&gt;%&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text-align: center&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;chkSelect&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create a list variable that will store ID's of selected rows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your code behind file, create a Private Property that will store the ID's of your selected rows:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; IDs() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
    &lt;span style="color: #008000"&gt;' Create a list of ID's that are selected.  ID's is the primary&lt;/span&gt;
    &lt;span style="color: #008000"&gt;' Key for this table&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;) = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)()
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;), List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;))
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Property&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create a Sub that will store the selected row ID's into your list variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we create a Sub that I called AddRowstoIDList which goes through all the currently visible rows and adds the ones that have a checkbox selected to the private list variable created in step 2. &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; AddRowstoIDList()
    &lt;span style="color: #008000"&gt;' Loop through all the current items in the Listview&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; lvi &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ListViewDataItem &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; ListView1.Items
        &lt;span style="color: #008000"&gt;' Find the checkbox in each row&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; chkSelect &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; CheckBox = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(lvi.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;chkSelect&amp;quot;&lt;/span&gt;), CheckBox)
        &lt;span style="color: #008000"&gt;' If the checkbox is ticked then add the corresponding ID to our private list&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; (chkSelect) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #008000"&gt;' Get the ID from the datakeynames property&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = 
            Convert.ToInt32(Listview1.DataKeys(lvi.DisplayIndex).Value)
            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (chkSelect.Checked &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #008000"&gt;' Add the ID to our list&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Add(ID)
            &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; chkSelect.Checked &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #008000"&gt;' Not checked - remove the ID from our list&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Remove(ID)
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;This sub is then called whenever the Listview is paged or sorted - we want to get the current status of the items and update our list before the Listview refreshes:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; ListView1_PagePropertiesChanging(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, 
        &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.Web.UI.WebControls.PagePropertiesChangingEventArgs) 
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Listview1.PagePropertiesChanging
    AddRowstoIDList()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; ListView1_Sorting(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, 
        &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.Web.UI.WebControls.ListViewSortEventArgs) 
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Listview1.Sorting
    AddRowstoIDList()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Make sure the checkboxes are displayed correctly when the Listview is refreshed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next step is to set the status of each checkbox correctly when the Listview is refreshed, by a sort of paging operation for example.&amp;#160; We do this by checking each item, finding the checkbox control, and checking it if the row ID exists in our list.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; ListView1_ItemDataBound(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, 
        &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.Web.UI.WebControls.ListViewItemEventArgs)
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Listview1.ItemDataBound
    &lt;span style="color: #008000"&gt;' Get each Listview Item on DataBound&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; lvi &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ListViewDataItem = e.Item
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (lvi.ItemType = ListViewItemType.DataItem) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' Find the checkbox in the current row&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; chkSelect &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; CheckBox = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(lvi.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;chkSelect&amp;quot;&lt;/span&gt;), CheckBox)
        &lt;span style="color: #008000"&gt;' Make sure we're referencing the correct control&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; (chkSelect) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #008000"&gt;' If the ID exists in our list then check the checkbox&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = Convert.ToInt32(ListView1.DataKeys(lvi.DisplayIndex).Value)
            chkSelect.Checked = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;That's it!&amp;#160; The code is very similar to the last article about the Gridview, but there are some gotcha's, particularly in how to reference items within the Gridview.&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="http://demo.evonet.com.au/MaintainingListviewCheckboxState.aspx"&gt;Demo&lt;/a&gt; or download the &lt;a href="http://demo.evonet.com.au/MaintainingListviewCheckboxState.rar"&gt;source code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/BN-zL6P68CE" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/08/10/Maintaining-Checkbox-State-in-a-Listview.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/08/10/Maintaining-Checkbox-State-in-a-Listview.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=efce7734-a4ab-4caf-87fb-e1ba4387229f</guid>
      <pubDate>Sun, 10 Aug 2008 21:13:00 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Listview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=efce7734-a4ab-4caf-87fb-e1ba4387229f</pingback:target>
      <slash:comments>10</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=efce7734-a4ab-4caf-87fb-e1ba4387229f</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/08/10/Maintaining-Checkbox-State-in-a-Listview.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=efce7734-a4ab-4caf-87fb-e1ba4387229f</wfw:commentRss>
    </item>
    <item>
      <title>Gridview with highlighted search results</title>
      <description>&lt;p&gt;Continuing on my Gridview series, the next project which had me reaching for Google was a requirement to highlight the returned search results in a Gridview.&amp;#160; &lt;/p&gt;  &lt;p&gt;Digging around, I found an article on 4guysfromRolla titled &lt;a href="http://aspnet.4guysfromrolla.com/articles/072402-1.aspx"&gt;Highlighting Search Keywords in a DataGrid Web Control&lt;/a&gt; which formed the basis of my work.&amp;#160; I ended up updating, simplying and modifing the code and decided to write a quick tutorial on how to highlight the text that a user searched for in the search results: &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p align="center"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="146" alt="image" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/Gridviewwithhighlightedsearchresults_12656/image_3.png" width="549" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://demo.evonet.com.au/GridviewwithHighlightedSearch.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/GridviewwithHighlightedSearch.rar"&gt;Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Create a Gridview&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Create a simple Gridview with TemplateFields for the fields that you would like to search for.&amp;#160; In my example I called the Gridview &lt;strong&gt;Gridview1 &lt;/strong&gt;and created a TemplateField for my two search fields, First Name and Last Name.&amp;#160; The other point of interest is that the Eval statement for these 2 fields is wrapped around a function that we're going to write called HighlightText.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AllowPaging&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;AllowSorting&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;540px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ID&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;First Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblFirstname&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# HighlightText(Eval(&amp;quot;FirstName&amp;quot;)) %&amp;gt;'&lt;/span&gt; 
                &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Last Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblLastname&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# HighlightText(Eval(&amp;quot;LastName&amp;quot;)) %&amp;gt;'&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create a datasource with a FilterExpression&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to enable our search functionality, add a FilterExpression to the datasource.&amp;#160; The FilterExpression that I'm using checks for the first name and last name against the Search Text box which will be created shortly.&amp;#160; And yes, I know I shouldn't use SQL statements in my Datasource, this is merely to make the example easier to demonstrate.&amp;#160; Normally&lt;em&gt;&amp;#160;&lt;/em&gt;I would use a multi-tier architecture with an ObjectDataSource such as something described by &lt;a href="http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416"&gt;Imar Spaanjaars&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SqlDataSource1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SELECT * FROM People&amp;quot;&lt;/span&gt;
    &lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;lt;%$ ConnectionStrings:ConnectionString %&amp;gt;&amp;quot;&lt;/span&gt;
    &lt;span style="color: #ff0000"&gt;FilterExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;firstname like '%{0}%' or lastname like '%{1}%'&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;FilterParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ControlParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;firstname&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PropertyName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Text&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ControlParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lastname&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PropertyName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Text&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;FilterParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The % characters in the FilterExpression are a wildcard to match any text before or after the search expression.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Add a Search Box&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This bit is easy, just create a textbox that you call txtSearch - this is what is referenced in our FilterExpression in Step 2.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ImageButton&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;btnSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ImageUrl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;images/searchbutton.png&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ImageButton&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;btnClear&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ImageUrl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;images/clearbutton.png&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Add code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The comments in the code below should be self-explanatory.&amp;#160; Basically every time we're displaying the First and Last name data in our Gridview, we check to see if there is any search text, and if there is, use a regular expression to enclose the search string in a CSS span which turns the text yellow.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Imports&lt;/span&gt; System.Text.RegularExpressions

Partial &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; GridviewwithHighlightedSearch
    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; System.Web.UI.Page

    &lt;span style="color: #008000"&gt;' Create a String to store our search results&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; SearchString &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt; = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; HighlightText(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; InputTxt &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' This function is called whenever text is displayed in the FirstName and LastName &lt;/span&gt;
        &lt;span style="color: #008000"&gt;' fields from our database. If we're not searching then just return the original &lt;/span&gt;
        &lt;span style="color: #008000"&gt;' input, this speeds things up a bit&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; SearchString = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; InputTxt
        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
            &lt;span style="color: #008000"&gt;' Otherwise create a new regular expression and evaluate the FirstName and &lt;/span&gt;
            &lt;span style="color: #008000"&gt;' LastName fields against our search string.&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ResultStr &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Regex
            ResultStr = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Regex(SearchString.Replace(&lt;span style="color: #006080"&gt;&amp;quot; &amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;|&amp;quot;&lt;/span&gt;), RegexOptions.IgnoreCase)
            &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; ResultStr.Replace(InputTxt, &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; MatchEvaluator(&lt;span style="color: #0000ff"&gt;AddressOf&lt;/span&gt; ReplaceWords))
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; ReplaceWords(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; m &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Match) &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' This match evaluator returns the found string and adds it a CSS class I defined &lt;/span&gt;
        &lt;span style="color: #008000"&gt;' as 'highlight'&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;span class=highlight&amp;gt;&amp;quot;&lt;/span&gt; + m.ToString + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/span&amp;gt;&amp;quot;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnClear_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt;  _
            System.Web.UI.ImageClickEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; btnClear.Click
        &lt;span style="color: #008000"&gt;' Simple clean up text to return the Gridview to it's default state&lt;/span&gt;
        txtSearch.Text = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        SearchString = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        Gridview1.DataBind()
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

    &lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnSearch_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt;  _
            System.Web.UI.ImageClickEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; btnSearch.Click
        &lt;span style="color: #008000"&gt;' Set the value of the SearchString so it gets &lt;/span&gt;
        SearchString = txtSearch.Text
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Add the CSS class for highlighting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final bit is to add the CSS claass referenced in the span called highlight.&amp;#160; In my case I'm simply turning the background of my text yellow:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;style&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
   .highlight {text-decoration: none;color:black;background:yellow;}
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's it!&amp;#160; I hope it helps you out, have a look at the &lt;a href="http://demo.evonet.com.au/GridviewwithHighlightedSearch.aspx"&gt;Demo&lt;/a&gt; and download the &lt;a href="http://demo.evonet.com.au/GridviewwithHighlightedSearch.rar"&gt;Source Code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.evonet.com.au%2fpost%2f2008%2f06%2fGridview-with-highlighted-search-results.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.evonet.com.au%2fpost%2f2008%2f06%2fGridview-with-highlighted-search-results.aspx&amp;amp;bgcolor=FF9933" border="0" /&gt;&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/un3Ldka2XQE" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/06/25/Gridview-with-highlighted-search-results.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/06/25/Gridview-with-highlighted-search-results.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=9bd76a43-dcdd-4c25-9dbb-f3b02c46588b</guid>
      <pubDate>Wed, 25 Jun 2008 22:03:48 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Gridview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=9bd76a43-dcdd-4c25-9dbb-f3b02c46588b</pingback:target>
      <slash:comments>8</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=9bd76a43-dcdd-4c25-9dbb-f3b02c46588b</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/06/25/Gridview-with-highlighted-search-results.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=9bd76a43-dcdd-4c25-9dbb-f3b02c46588b</wfw:commentRss>
    </item>
    <item>
      <title>Error when exporting a Gridview to Excel when using Master Pages</title>
      <description>&lt;p&gt;If you have a Gridview that exports rows to Excel (see my article &lt;a href="http://blog.evonet.com.au/post/2008/06/Gridview-that-exports-selected-rows-to-Excel.aspx"&gt;Gridview that exports selected rows to Excel&lt;/a&gt; for an example) and you are using Master Pages, you are likely to run into the following error:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&amp;quot;Control 'ctl00_MainContent_Gridview1' of type 'GridView' must be placed inside a form tag with runat=server&amp;quot;, &lt;/em&gt;even though you have the supposedly missing form tag.&lt;/p&gt;  &lt;p&gt;The reason for this is described in &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.verifyrenderinginserverform(vs.71).aspx"&gt;this MSDN page&lt;/a&gt; and occurs because ASP.NET does not know to render this control at run time.&lt;/p&gt;  &lt;p&gt;Simply adding the following empty function will override the default behaviour:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Overloads&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Overrides&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; VerifyRenderingInServerForm(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; control &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Control)
        &lt;span style="color: #008000"&gt;' Nothing needed here...&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Note that this will only occur if you are using Master Pages.&lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/t5W66EEYWhM" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/06/19/Error-when-exporting-a-Gridview-to-Excel-when-using-Master-Pages.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/06/19/Error-when-exporting-a-Gridview-to-Excel-when-using-Master-Pages.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=a25138e1-4357-4ab2-9e30-01cf2b4de6b9</guid>
      <pubDate>Thu, 19 Jun 2008 16:23:10 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Gridview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=a25138e1-4357-4ab2-9e30-01cf2b4de6b9</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=a25138e1-4357-4ab2-9e30-01cf2b4de6b9</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/06/19/Error-when-exporting-a-Gridview-to-Excel-when-using-Master-Pages.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=a25138e1-4357-4ab2-9e30-01cf2b4de6b9</wfw:commentRss>
    </item>
    <item>
      <title>Gridview that exports selected rows to Excel</title>
      <description>&lt;p&gt;I recently had a project where I needed to provide a Gridview of items that the customer could individually select and export to Excel.&amp;#160; The solution worked really well, so here it is for all to enjoy...&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This seems like a messy workaround, but I ended up using two Gridviews - one to display my data and show my checkboxes, and the other which was invisible amd would eventually end up as my Excel spreadsheet.&amp;#160; Why two?&amp;#160; Well... &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The export to Excel uses the Response.Write class which doesn't work under AJAX&amp;#160; (to my knowledge anyway).&amp;#160; Having the first Gridview in an UpdatePanel provides a better user experience when sorting and paging.&amp;#160; The second Gridview is outside the UpdatePanel and invisible. &lt;/li&gt;    &lt;li&gt;The 2 Gridviews are formatted differently.&amp;#160; As an example, the Gridview that is exported to Excel doesn't need sorting or paging options, nor the checkboxes that are used to select rows.&amp;#160; Also, the colours used in your website may not be ideal for an Excel spreadsheet. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://demo.evonet.com.au/GridviewwithSelectedExport.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/GridviewwithSelectedExport.rar"&gt;Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Create a Gridview with selectable rows&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The first Gridview is the one that you will be displaying on your webpage (I use the same table and CSS structure as in my article on &lt;a href="http://blog.evonet.com.au/post/2008/05/Creating-a-Stylish-looking-Gridview-with-Filtering.aspx"&gt;Creating a great looking Gridview with filtering&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;I called this Gridview gvData.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p align="center"&gt;&amp;#160;&lt;img height="417" alt="Gridview that exports selected rows to Excel" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/BuildingaGridviewthatexportsselectedrows_12C6F/image_7.png" width="549" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GridView1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AllowPaging&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;AllowSorting&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EmptyDataText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;No records to display.&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;540px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ID&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;RowStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;data-row&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;AlternatingRowStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;alt-data-row&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;HeaderStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;header-row&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ID&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;First Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;110px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Last Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;110px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Dept&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;chkSelect&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The main point of interest is the checkbox that is included as a field:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;chkSelect&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You also need to set the Datakeynames property to the ID of your primary database key.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create an invisible Gridview that will be exported to Excel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This Gridview is the one that will be exported to Excel.&amp;#160; The main things to note are the changes to the Gridview properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Disable paging &lt;/li&gt;

  &lt;li&gt;Disable sorting &lt;/li&gt;

  &lt;li&gt;Set visible = 'True' &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once again, set datakeynames to the ID of your primary database key.&amp;#160; &lt;/p&gt;

&lt;p&gt;You also don't need the checkbox template field.&lt;/p&gt;

&lt;p&gt;I called this gvExporttoExcel.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p align="center"&gt;&lt;img height="208" alt="Gridview that exports selected rows to Excel" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/BuildingaGridviewthatexportsselectedrows_12C6F/image_6.png" width="549" border="0" /&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GridView1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AllowPaging&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EmptyDataText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;There are no records to display.&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;690px&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ID&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Visible&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;120px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;PagerSettings&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Mode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;NumericFirstLast&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageButtonCount&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Set EnableEventValidation=&amp;quot;false&amp;quot;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your page declarations, set EnableEventValidation='false', otherwise you will get the error: &lt;i&gt;RegisterForEventValidation can only be called during Render();&lt;/i&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;%@ Page Language=&lt;span style="color: #006080"&gt;&amp;quot;VB&amp;quot;&lt;/span&gt; CodeFile=&lt;span style="color: #006080"&gt;&amp;quot;GridviewwithSelectedExport.aspx.vb&amp;quot;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt;=&lt;span style="color: #006080"&gt;&amp;quot;GridviewwithSelectedExport&amp;quot;&lt;/span&gt; EnableEventValidation=&lt;span style="color: #006080"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; %&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You will also need to create an empty sub that overrides the Gridview's Render process:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Overloads&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Overrides&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; VerifyRenderingInServerForm(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; control &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Control)
     &lt;span style="color: #008000"&gt;' Nothing needed here...&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Create a list variable that will store ID's of selected rows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your code behind file, create a Private Property that will store the ID's of your selected rows:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Property&lt;/span&gt; IDs() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)
    &lt;span style="color: #008000"&gt;' Create a list of ID's that are selected.  ID's is the primary&lt;/span&gt;
    &lt;span style="color: #008000"&gt;' Key for this table&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;) = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;)()
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.ViewState(&lt;span style="color: #006080"&gt;&amp;quot;IDs&amp;quot;&lt;/span&gt;), List(Of &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;))
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Get&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Property&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Create a Sub that will store the selected row ID's into your list variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we create a Sub that I called AddRowstoIDList which goes through all the currently visible rows and adds the ones that have a checkbox selected to the private list variable created in step 4. &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; AddRowstoIDList()
    &lt;span style="color: #008000"&gt;' Loop through all the currently displayed rows in the Gridview&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; gvr &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; GridViewRow &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; gvData.Rows
        &lt;span style="color: #008000"&gt;' Find the checkbox in each row&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; chkSelect &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; CheckBox = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(gvr.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;chkSelect&amp;quot;&lt;/span&gt;), CheckBox)
        &lt;span style="color: #008000"&gt;' If the checkbox is ticked then add the corresponding ID to our private list&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; (chkSelect) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #008000"&gt;' Get the ID from the datakeynames property&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = Convert.ToInt32(gvData.DataKeys(gvr.RowIndex)(&lt;span style="color: #006080"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;))
            &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (chkSelect.Checked &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #008000"&gt;' Add the ID to our list&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Add(ID)
            &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; chkSelect.Checked &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #008000"&gt;' Not checked - remove the ID from our list&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Remove(ID)
            &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This sub is then called whenever the Gridview is paged or sorted - we want to get the current status of the rows and update our list before the Gridview refreshes:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Gridview1_PageIndexChanging(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &amp;amp; _
        &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; GridViewPageEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; gvData.PageIndexChanging
    AddRowstoIDlist()
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Gridview1_Sorting(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &amp;amp; _
        System.Web.UI.WebControls.GridViewSortEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; gcData.Sorting
    AddRowstoIDlist()
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Make sure the checkboxes are displayed correctly when the Gridview is refreshed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next step is to set the status of each checkbox correctly when the Gridview is refreshed, by a sort of paging operation for example.&amp;#160; We do this by checking each row, finding the checkbox control, and checking it if the row ID exists in our list.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; gvData_RowDataBound(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; GridViewRowEventArgs) &amp;amp; _
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; gvData.RowDataBound
    &lt;span style="color: #008000"&gt;' Get each Gridview Row on DataBound&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; gvr &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; GridViewRow = e.Row
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (gvr.RowType = DataControlRowType.DataRow) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' Find the checkbox in the current row&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; chkSelect &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; CheckBox = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(gvr.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;chkSelect&amp;quot;&lt;/span&gt;), CheckBox)
        &lt;span style="color: #008000"&gt;' Make sure we're referencing the correct control&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; (chkSelect) &lt;span style="color: #0000ff"&gt;Is&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Nothing&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            &lt;span style="color: #008000"&gt;' If the ID exists in our list then check the checkbox&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = Convert.ToInt32(gvData.DataKeys(gvr.RowIndex)(&lt;span style="color: #006080"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;))
            chkSelect.Checked = &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID)
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Create a download button that exports the selected rows to Excel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, create a download button anywhere on your page:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:LinkButton&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;btnDownload&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Download selected rows to Excel&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The next bit of code manipulates our hidden Gridview (gvExporttoExcel) by making visible any rows that are marked for export, then writing those to an Excel file.&lt;/p&gt;

&lt;p&gt;Add the following code behind to export the data to Excel:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; btnDownload_Click(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.EventArgs) &amp;amp; _
        &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; btnDownload.Click
    &lt;span style="color: #008000"&gt;' First, check the contents of the current Gridview page to make sure that&lt;/span&gt;
    &lt;span style="color: #008000"&gt;' all the checked items are in our list.  We need this as the user may have checked or &lt;/span&gt;
    &lt;span style="color: #008000"&gt;' unchecked records since the last paging or sorting operation.&lt;/span&gt;
    AddRowstoIDList()
    &lt;span style="color: #008000"&gt;' Loop through our second Gridview, and make visible any row where the ID of the record&lt;/span&gt;
    &lt;span style="color: #008000"&gt;' is in our list of checked records&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; gvr &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; GridViewRow &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; gvExporttoExcel.Rows
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; ID &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt; = Convert.ToInt32(gvExporttoExcel.DataKeys(gvr.RowIndex)(&lt;span style="color: #006080"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;))
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Contains(ID) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
            gvr.Visible = &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
            gvr.Visible = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Me&lt;/span&gt;.IDs.Count = 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' Display an error here if you like&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;Else&lt;/span&gt;
        gvExporttoExcel.Visible = &lt;span style="color: #0000ff"&gt;True&lt;/span&gt;
        &lt;span style="color: #008000"&gt;' Write the gridview to Excel&lt;/span&gt;
        Response.Clear()
        Response.AddHeader(&lt;span style="color: #006080"&gt;&amp;quot;content-disposition&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;attachment;filename=FileName.xls&amp;quot;&lt;/span&gt;)
        Response.Charset = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = &lt;span style="color: #006080"&gt;&amp;quot;application/vnd.xls&amp;quot;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; stringWrite &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; System.IO.StringWriter()
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; htmlWrite &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.Web.UI.HtmlTextWriter = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; HtmlTextWriter(stringWrite)
        gvExporttoExcel.RenderControl(htmlWrite)
        Response.Write(stringWrite.ToString())
        Response.&lt;span style="color: #0000ff"&gt;End&lt;/span&gt;()
        gvExporttoExcel.Visible = &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;p&gt;That should be it!&amp;#160; Check out the &lt;a href="http://demo.evonet.com.au/GridviewwithSelectedExport.aspx"&gt;Demo&lt;/a&gt; or download the &lt;a href="http://demo.evonet.com.au/GridviewwithSelectedExport.rar"&gt;source code&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.evonet.com.au%2fpost%2f2008%2f06%2fGridview-that-exports-selected-rows-to-Excel.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.evonet.com.au%2fpost%2f2008%2f06%2fGridview-that-exports-selected-rows-to-Excel.aspx&amp;amp;bgcolor=FF9933" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/HYcuVnKWiYY" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/06/17/Gridview-that-exports-selected-rows-to-Excel.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/06/17/Gridview-that-exports-selected-rows-to-Excel.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=e95661a1-59dd-464e-98b5-efbab2ff3383</guid>
      <pubDate>Tue, 17 Jun 2008 11:16:06 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Gridview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=e95661a1-59dd-464e-98b5-efbab2ff3383</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=e95661a1-59dd-464e-98b5-efbab2ff3383</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/06/17/Gridview-that-exports-selected-rows-to-Excel.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=e95661a1-59dd-464e-98b5-efbab2ff3383</wfw:commentRss>
    </item>
    <item>
      <title>'dropdownlist1' has a SelectedValue which is invalid because it does not exist in the list of items</title>
      <description>&lt;p&gt;When you bind a dropdownlist to a table of data, and you try to edit an entry that contains data that has been deleted, you invariably will run into the error: 'dropdownlist1' has a SelectedValue which is invalid because it does not exist in the list of items. &lt;/p&gt;  &lt;p&gt;Consider the following example: &lt;/p&gt;  &lt;p&gt;You have a series of Events that are displayed in a calendar, where each event can have a Category.&amp;#160; You provide your users the ability to edit their events, and administrators the ability to edit categories. &lt;/p&gt;  &lt;p&gt;When creating a new event you would have a dropdownlist that references the categories table like so:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddlCategory&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;SelectedValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind(&amp;quot;Category&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateEventCategories&amp;quot;&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;DataTextField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataValueField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Please Select&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateEventCategories&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;lt;%$ ConnectionStrings:EvonetConnectionString %&amp;gt;&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SELECT Name from [T_Categories]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The same code would be used in your EditItemTemplate for your Formview in case the user wants to change the category.&amp;#160; But if an administrator deletes or renames the category in the meantime then you get the following error: &lt;/p&gt;

&lt;p&gt;'ddlCategory' has a SelectedValue which is invalid because it does not exist in the list of items &lt;/p&gt;

&lt;p&gt;This is basically because the dropdownlist populates the categories from the category table - and the category that you have bound to your dropdownlist doesn't exist in that table. &lt;/p&gt;

&lt;p&gt;To solve the problem neatly, first of all remove the SelectedValue property for your dropdownlist to remove your binding.&amp;#160; Your dropdownlist then beomes:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddlCategory&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt;
    &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateEventCategories&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataTextField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataValueField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt;
    &lt;span style="color: #ff0000"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Please Select&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Secondly, in the PreRender subroutine for your Formview, add some code which will search through the data items bound to your dropdownlist, and if your category isn't found then display the &amp;quot;Please Select&amp;quot; option:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Formview1_PreRender(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.EventArgs) &amp;amp; _ 
    &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Formview1.PreRender
    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; Formview1.CurrentMode = FormViewMode.Edit &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; rowView &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DataRowView = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1.DataItem, DataRowView)
        &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; IsNothing(rowView) &lt;span style="color: #0000ff"&gt;AndAlso&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Not&lt;/span&gt; IsNothing(&lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1. &amp;amp; _
            FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ddlCategory&amp;quot;&lt;/span&gt;), DropDownList).Items. &amp;amp; _
            FindByValue(rowView(&lt;span style="color: #006080"&gt;&amp;quot;Category&amp;quot;&lt;/span&gt;).ToString())) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ddlCategory&amp;quot;&lt;/span&gt;), DropDownList).SelectedValue &amp;amp; _ 
                    = rowView(&lt;span style="color: #006080"&gt;&amp;quot;Category&amp;quot;&lt;/span&gt;).ToString()
        &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The final step is to save the selected category back into the database when the user clicks the Save button to complete editing:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Formview1_ItemUpdating(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &amp;amp; _
    System.Web.UI.WebControls.FormViewUpdateEventArgs) &amp;amp; _
    &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Formview1.ItemUpdating
        e.NewValues(&lt;span style="color: #006080"&gt;&amp;quot;Category&amp;quot;&lt;/span&gt;) = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(formview1.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ddlCategory&amp;quot;&lt;/span&gt;), &amp;amp; _
            DropDownList).SelectedValue
&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Hope this helps! &lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/HOAqqMEpBxM" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/06/07/dropdownlist1-has-a-SelectedValue-which-is-invalid-because-it-does-not-exist-in-the-list-of-items.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/06/07/dropdownlist1-has-a-SelectedValue-which-is-invalid-because-it-does-not-exist-in-the-list-of-items.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=a2141526-ecf7-404c-8861-187a388b7164</guid>
      <pubDate>Sat, 07 Jun 2008 14:21:06 +1100</pubDate>
      <category>ASP.NET</category>
      <category>DropDownList</category>
      <category>Formview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=a2141526-ecf7-404c-8861-187a388b7164</pingback:target>
      <slash:comments>13</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=a2141526-ecf7-404c-8861-187a388b7164</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/06/07/dropdownlist1-has-a-SelectedValue-which-is-invalid-because-it-does-not-exist-in-the-list-of-items.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=a2141526-ecf7-404c-8861-187a388b7164</wfw:commentRss>
    </item>
    <item>
      <title>Creating a great looking Gridview with filtering</title>
      <description>&lt;p&gt;Matt Berseth (&lt;a href="http://www.mattberseth.com/"&gt;http://www.mattberseth.com/&lt;/a&gt;) has some of the best ASP.NET 2.0 articles around, and his examples are always well documented. &lt;/p&gt;  &lt;p&gt;Matt recently wrote some articles about how to a design good looking Gridview's (&lt;a href="http://mattberseth.com/blog/2008/04/building_a_vs2008_styled_grid_1.html"&gt;Building a vs2008 Styled Grid&lt;/a&gt; and &lt;a href="http://mattberseth.com/blog/2007/11/5_gridview_themes_based_on_goo.html"&gt;Gridview Themes based on Google's Personalized Homepage&lt;/a&gt;) which was exactly what I was after. &lt;/p&gt;  &lt;p&gt;I have been looking for quite some time for a good looking Gridview and Matt's were great, although they didn't include any filtering. Nearly all of my Gridviews have filtering enabled and so here is a quick tutorial to show you how to design a stylish Gridview based on Matt's design with filtering enabled for some of the columns. &lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaStylishlookingGridviewwithFilte_13434/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="226" alt="image" src="http://blog.evonet.com.au/image.axd?picture=WindowsLiveWriter/CreatingaStylishlookingGridviewwithFilte_13434/image_thumb_4.png" width="548" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://demo.evonet.com.au/GridviewwithFiltering.aspx"&gt;Demo&lt;/a&gt; | &lt;a href="http://demo.evonet.com.au/GridviewwithFiltering.rar"&gt;Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Create the Gridview and Datasource &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Create a simple Gridview and Datasouce.&amp;#160; In this example I am using a SQL Datasource, but I recommend using a ObjectDataSource for production environments.&amp;#160; Set the ConnectionString to the value in your web.config file and the ItemStyle-Width for each of your fields depending on the type of data and how much space you have.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AllowPaging&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;AllowSorting&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;650px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;20&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; 
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;
        &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SqlDataSource1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;lt;%$ ConnectionStrings:EvonetConnectionString %&amp;gt;&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SELECT * FROM [T_Employees]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create the table used for the Gridview headers &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we create a simple table to hold the headings and filter drop down boxes.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 650px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;border&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellpadding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;cellspacing&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GridviewTable&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 50px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        ID
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        First Name
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        Last Name
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        Department
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        Location
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 50px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddldepartment&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateDepartment&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataValueField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;Font-Size&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;11px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;All&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;%&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;width: 150px;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddlLocation&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateLocation&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataValueField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;Font-Size&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;11px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;All&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;%&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt; &lt;span style="color: #ff0000"&gt;colspan&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;AllowPaging&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AllowSorting&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;650px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PageSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Gridview&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;id&amp;quot;&lt;/span&gt; 
                    &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-HorizontalAlign&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; 
                    &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;FirstName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; 
                    &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LastName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; 
                    &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:BoundField&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;HeaderText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort&amp;quot;&lt;/span&gt; 
                    &lt;span style="color: #ff0000"&gt;SortExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;150px&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Columns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;td&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;tr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;table&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;For the last cell, set the td colspan value to the number of fields in your Gridview.&amp;#160; Move your Gridview into that last cell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create the style sheet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The stylesheet that I use has the following items:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #cc6633"&gt;.GridviewDiv&lt;/span&gt; {&lt;span style="color: #0000ff"&gt;font-size&lt;/span&gt;: &lt;span style="color: #006080"&gt;62.5%;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;font-family&lt;/span&gt;: 'Lucida Grande', 
    'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans&lt;span style="color: #006080"&gt;-serif;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;color&lt;/span&gt;: &lt;span style="color: #006080"&gt;#303933;&lt;/span&gt;}
Table&lt;span style="color: #cc6633"&gt;.Gridview&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;:&lt;span style="color: #006080"&gt;solid 1px #df5015;&lt;/span&gt;}
&lt;span style="color: #cc6633"&gt;.GridviewTable&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;:none}
&lt;span style="color: #cc6633"&gt;.GridviewTable&lt;/span&gt; &lt;span style="color: #0000ff"&gt;td&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;margin&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;top&lt;/span&gt;:0;&lt;span style="color: #0000ff"&gt;padding&lt;/span&gt;: 0; &lt;span style="color: #0000ff"&gt;vertical-align&lt;/span&gt;:middle }
&lt;span style="color: #cc6633"&gt;.GridviewTable&lt;/span&gt; &lt;span style="color: #0000ff"&gt;tr&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;: &lt;span style="color: #006080"&gt;White;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;background-color&lt;/span&gt;: &lt;span style="color: #006080"&gt;#df5015;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;height&lt;/span&gt;: &lt;span style="color: #006080"&gt;30px;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;text-align&lt;/span&gt;:&lt;span style="color: #0000ff"&gt;center&lt;/span&gt;}
&lt;span style="color: #cc6633"&gt;.Gridview&lt;/span&gt; &lt;span style="color: #0000ff"&gt;th&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;:&lt;span style="color: #006080"&gt;#FFFFFF;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;right&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;:&lt;span style="color: #006080"&gt;#abb079;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;bottom&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;:&lt;span style="color: #006080"&gt;#abb079;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;padding&lt;/span&gt;:&lt;span style="color: #006080"&gt;0.5em 0.5em 0.5em 0.5em;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;text-align&lt;/span&gt;:&lt;span style="color: #0000ff"&gt;center&lt;/span&gt;}  
&lt;span style="color: #cc6633"&gt;.Gridview&lt;/span&gt; &lt;span style="color: #0000ff"&gt;td&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;bottom&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;:&lt;span style="color: #006080"&gt;#f0f2da;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;border&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;right&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;:&lt;span style="color: #006080"&gt;#f0f2da;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;padding&lt;/span&gt;:&lt;span style="color: #006080"&gt;0.5em 0.5em 0.5em 0.5em;&lt;/span&gt;}
&lt;span style="color: #cc6633"&gt;.Gridview&lt;/span&gt; &lt;span style="color: #0000ff"&gt;tr&lt;/span&gt;{&lt;span style="color: #0000ff"&gt;color&lt;/span&gt;: &lt;span style="color: #006080"&gt;Black;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;background-color&lt;/span&gt;: &lt;span style="color: #006080"&gt;White;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;text-align&lt;/span&gt;:&lt;span style="color: #0000ff"&gt;left&lt;/span&gt;}
:&lt;span style="color: #0000ff"&gt;link&lt;/span&gt;,:visited { &lt;span style="color: #0000ff"&gt;color&lt;/span&gt;: &lt;span style="color: #006080"&gt;#DF4F13;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;text-decoration&lt;/span&gt;:none }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You should be able to just copy this into your css file without it affecting your exiting style sheets, although be careful if you have already set :link and :visited in your site. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Add the filtering drop down boxes and data sources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the table created in Step 2, add a dropdownlist to each of the cells in the second row that contain the field you want to filter.&amp;#160; Make sure eac dropdownlist is smaller than the cell it is going into, otherwise your table borders will not be aligned.&amp;#160; Set up a datasource which gets the each possible value of that field within your table.&amp;#160; I do this by running a DISTINCT for all values in the table I am filtering:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddldepartment&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataSourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateDepartment&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataValueField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;130px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Font-Size&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;11px&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;All&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;%&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsPopulateDepartment&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;lt;%$ ConnectionStrings:EvonetConnectionString %&amp;gt;&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SELECT 
DISTINCT Department from [T_Employees]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Create as many dropdownlists as fields that you would like to filter by. &lt;/p&gt;

&lt;p&gt;A few things to note: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Set the AppendDataBoundItems=True property for your dropdownlist as it will be filled at runtime.&amp;#160; &lt;/li&gt;

  &lt;li&gt;Set the AutoPostBack=True property so that the Gridview is refreshed when the selection changes. &lt;/li&gt;

  &lt;li&gt;Make sure your ListItem for 'All' has '%' as the value.&amp;#160; Your filter expression will be SELECT * FROM [TABLE NAME] Where [FieldName] like '{0}%' where {0} is the value in your dropdownlist.&amp;#160; If your dropdownlist is set to all then the query string will be SELECT * FROM [TABLE NAME] Where [FieldName] like '%%' which, in SQL returns all values. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Add filtering to your Gridview's Datasource&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add a FilterExpress so your Gridview's Datasource such as &lt;/p&gt;

&lt;p&gt;[Field1] like '{0}%' and [Field2] like '{1}%' and [Field3] like '{2}%' and [Field4] like '{3}%' and ... etc &lt;/p&gt;

&lt;p&gt;Your fields then need to be added to the FilterParameters section in the same order as your filter expression.&amp;#160; The FilterParameters section references the SelectedValue of your dropdownlists.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;dsGridview&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
    &lt;span style="color: #ff0000"&gt;ConnectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;lt;%$ ConnectionStrings:EvonetConnectionString %&amp;gt;&amp;quot;&lt;/span&gt;
    &lt;span style="color: #ff0000"&gt;SelectCommand&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SELECT * FROM [T_Employees]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FilterExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department like '{0}%'
    and Location like '{1}%'&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;FilterParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ControlParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Department&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddldepartment&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;PropertyName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SelectedValue&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ControlParameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddllocation&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #ff0000"&gt;PropertyName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SelectedValue&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;FilterParameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;That's it!&amp;#160; Check out the &lt;a href="http://demo.evonet.com.au/GridviewwithFiltering.aspx"&gt;Demo&lt;/a&gt; or download the &lt;a href="http://demo.evonet.com.au/GridviewwithFiltering.rar"&gt;source code&lt;/a&gt; and have a play. &lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/YdmEuolmd_Q" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/05/31/Creating-a-Stylish-looking-Gridview-with-Filtering.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/05/31/Creating-a-Stylish-looking-Gridview-with-Filtering.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=c51d57e1-f7a5-444e-95e2-660104f407a3</guid>
      <pubDate>Sat, 31 May 2008 12:21:29 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Gridview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=c51d57e1-f7a5-444e-95e2-660104f407a3</pingback:target>
      <slash:comments>14</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=c51d57e1-f7a5-444e-95e2-660104f407a3</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/05/31/Creating-a-Stylish-looking-Gridview-with-Filtering.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=c51d57e1-f7a5-444e-95e2-660104f407a3</wfw:commentRss>
    </item>
    <item>
      <title>Using CultureInvariantValues = true</title>
      <description>&lt;p&gt;I ran into a frustrating error recently, where my compare validator was refusing to co-operate when testing 2 dates. &lt;/p&gt;  &lt;p&gt;Here is my code: &lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Start date: 
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtStartDate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;80px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind(&amp;quot;startdate&amp;quot;,&amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
End date: 
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtenddate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;80px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind(&amp;quot;enddate&amp;quot;,&amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CompareValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CompareValidator1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToCompare&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtstartdate&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtenddate&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;Operator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GreaterThanEqual&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;The start date has to be before the end date&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The problem was that the Compare Validator would not work when the start date was 05/06/2008 and the end date was 03/07/2008 (these are all in DD/MM/YYYY).&amp;#160; The reason was that the compare validator did not realise the value was a date and saw simply that 05 was greater than 03 in terms of ASCII values.&amp;#160; &lt;/p&gt;

&lt;p&gt;The fix should have been simply to add type=&amp;quot;date&amp;quot; to the CompareValidator, however on it's own that doesn't work if you're using UK English dates - you also need to add CultureInvariantValues=&amp;quot;true&amp;quot; (unless your Globalisation is set properly in your web.config - which mine wasn't...) &lt;/p&gt;

&lt;p&gt;The full code then becomes: &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Start date: 
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtStartDate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;80px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind(&amp;quot;startdate&amp;quot;,&amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
End date: 
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtenddate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;80px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextField&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Bind(&amp;quot;enddate&amp;quot;,&amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:CompareValidator&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CompareValidator2&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ControlToCompare&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtstartdate&amp;quot;&lt;/span&gt; 
&lt;span style="color: #ff0000"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtenddate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CultureInvariantValues&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Date&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;Operator&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GreaterThanEqual&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;The start date has to be before the end date&amp;quot;&lt;/span&gt;
&lt;span style="color: #ff0000"&gt;Display&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;MSDN has more information here: &lt;a href="http://msdn.microsoft.com/en-us/library/a7zyyk0c(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/a7zyyk0c(VS.80).aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/rJxcehiVksI" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/05/24/Using-CultureInvariantValues3dquot3btruequot3b-in-a-CompareValidator.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/05/24/Using-CultureInvariantValues3dquot3btruequot3b-in-a-CompareValidator.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=53529987-e42d-4e09-b15a-ffadc7a630c3</guid>
      <pubDate>Sat, 24 May 2008 11:32:01 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Validation</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=53529987-e42d-4e09-b15a-ffadc7a630c3</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=53529987-e42d-4e09-b15a-ffadc7a630c3</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/05/24/Using-CultureInvariantValues3dquot3btruequot3b-in-a-CompareValidator.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=53529987-e42d-4e09-b15a-ffadc7a630c3</wfw:commentRss>
    </item>
    <item>
      <title>Editing date and time in a Formview</title>
      <description>&lt;p&gt;This is a simple example for how to provide an editing interface for date and time fields.&amp;#160; &lt;/p&gt;  &lt;p&gt;Say that you are storing Booking details and your BookingDate field contains both the date and time, eg '21/05/2008 10:30:00 AM' &lt;/p&gt;  &lt;p&gt;If you wanted to display the date and time strings seperately you can do this in a formview quite easily: &lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Date: &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblDate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Eval(&amp;quot;bookingdate&amp;quot;, &amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
Time:&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblTime&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Eval(&amp;quot;bookingdate&amp;quot;, &amp;quot;{0:%h:mm ttt}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;But to edit the date and time you would use a normal date field (with your choice of date picker) and then a dropdownlist for the time: &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Date: 
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtDate&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;='&amp;lt;%# Eval(&amp;quot;bookingdate&amp;quot;, &amp;quot;{0:d}&amp;quot;) %&amp;gt;'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
Time:
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddlHours&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Font-Size&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;11px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;07&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;08&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;09&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;10&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;11&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;12&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;13&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;14&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;15&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;16&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;17&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;18&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;19&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;20&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ddlMins&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;40px&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Font-Size&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;11px&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;00&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;05&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;10&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;15&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;20&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;25&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;30&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;35&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;40&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;45&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;50&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;55&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:ListItem&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:DropDownList&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Note the use of 'Eval' in the BookingDate Textbox - normally you would use 'Bind' for 2 way databinding, but we don't want to store the date - we want to store a combination of the date and time in the same field, which is done in the Formview's ItemUpdating subroutine: &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; Formview1_ItemUpdating(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; e &amp;amp; _
&lt;span style="color: #0000ff"&gt;As&lt;/span&gt; System.Web.UI.WebControls.FormViewUpdateEventArgs) &lt;span style="color: #0000ff"&gt;Handles&lt;/span&gt; Formview1.ItemUpdating
    e.NewValues(&lt;span style="color: #006080"&gt;&amp;quot;bookingdate&amp;quot;&lt;/span&gt;) = &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;txtBookingDate&amp;quot;&lt;/span&gt;), TextBox).Text &amp;amp; _
        &lt;span style="color: #006080"&gt;&amp;quot; &amp;quot;&lt;/span&gt; &amp;amp; &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ddlHours&amp;quot;&lt;/span&gt;), DropDownList).SelectedValue &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;:&amp;quot;&lt;/span&gt; &amp;amp; _
        &lt;span style="color: #0000ff"&gt;CType&lt;/span&gt;(Formview1.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ddlMins&amp;quot;&lt;/span&gt;), DropDownList).SelectedValue
&lt;span style="color: #0000ff"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This simply combines the textbox and dropdownlists into a formatted date which is then saved in your database as BookingDate. &lt;/p&gt;

&lt;p&gt;Bartek Marnane&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Evonet/~4/Td05LrBs_Ys" height="1" width="1"/&gt;</description>
      <link>http://blog.evonet.com.au/post/2008/05/17/Editing-date-and-time-in-a-Formview.aspx</link>
      <author>bartek.nospam@nospam.evonet.com.au (bartek)</author>
      <comments>http://blog.evonet.com.au/post/2008/05/17/Editing-date-and-time-in-a-Formview.aspx#comment</comments>
      <guid>http://blog.evonet.com.au/post.aspx?id=2dd0f132-6696-4f04-92d4-fdf68b55fc5e</guid>
      <pubDate>Sat, 17 May 2008 11:17:11 +1100</pubDate>
      <category>ASP.NET</category>
      <category>Formview</category>
      <dc:publisher>bartek</dc:publisher>
      <pingback:server>http://blog.evonet.com.au/pingback.axd</pingback:server>
      <pingback:target>http://blog.evonet.com.au/post.aspx?id=2dd0f132-6696-4f04-92d4-fdf68b55fc5e</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.evonet.com.au/trackback.axd?id=2dd0f132-6696-4f04-92d4-fdf68b55fc5e</trackback:ping>
      <wfw:comment>http://blog.evonet.com.au/post/2008/05/17/Editing-date-and-time-in-a-Formview.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.evonet.com.au/syndication.axd?post=2dd0f132-6696-4f04-92d4-fdf68b55fc5e</wfw:commentRss>
    </item>
  </channel>
</rss>
