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

<channel>
	<title>Coming up blank &#187; CSS</title>
	<atom:link href="http://damianedwards.wordpress.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://damianedwards.wordpress.com</link>
	<description>Thoughts on web standards, ASP.NET and team development - Damian Edwards</description>
	<lastBuildDate>Wed, 16 Sep 2009 02:06:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='damianedwards.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/37a95f90b01f20bf410ee80ac0575ef6?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Coming up blank &#187; CSS</title>
		<link>http://damianedwards.wordpress.com</link>
	</image>
			<item>
		<title>Set the CSS class of ASP.NET invalid controls using jQuery</title>
		<link>http://damianedwards.wordpress.com/2009/01/31/set-the-css-class-of-aspnet-invalid-controls-using-jquery/</link>
		<comments>http://damianedwards.wordpress.com/2009/01/31/set-the-css-class-of-aspnet-invalid-controls-using-jquery/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 12:08:15 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/2009/01/31/set-the-css-class-of-aspnet-invalid-controls-using-jquery/</guid>
		<description><![CDATA[The ASP.NET validation controls are a very quick and effective way to add client-side &#38; server-side validation to your web forms but they lack one very important feature out of the box: the ability to change the CSS class of the controls that are invalid. Changing the class of the invalid controls will allow you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=75&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The ASP.NET validation controls are a very quick and effective way to add client-side &amp; server-side validation to your web forms but they lack one very important feature out of the box: the ability to change the CSS class of the controls that are invalid. Changing the class of the invalid controls will allow you to style them in such a way that they help bring attention to the fact that the user needs to do something more to complete the form successfully.</p>
<p>It is quite simple to add this functionality (for clients with JavaScript enabled at least) using a little bit of JavaScript and everybody’s favourite JavaScript library, jQuery!</p>
<p>First of all, set the CssClass property of all your validator controls to “validation-error”. The easiest way to achieve this is by using a skin file. See <a href="http://damianedwards.wordpress.com/2008/02/10/aspnet-css-using-skins-to-zero-out-default-style-and-set-default-css-class-names/">this post</a> for more details on how to do this.</p>
<p>Then add the following to your site’s JavaScript file (assuming you’re already using jQuery):</p>
<pre class="brush: jscript;">
/// &lt;reference path=&quot;jquery-1.3.1.js&quot; /&gt;

$(document).ready(function(e) {
    $(&quot;span.validation-error&quot;)
        .bind(&quot;DOMAttrModified propertychange&quot;, function(e) {
            // Exit early if IE because it throws this event lots more
            if (e.originalEvent.propertyName &amp;&amp; e.originalEvent.propertyName != &quot;isvalid&quot;) return;

            var controlToValidate = $(&quot;#&quot; + this.controltovalidate);
            var validators = controlToValidate.attr(&quot;Validators&quot;);
            if (validators == null) return;

            var isValid = true;
            $(validators).each(function() {
                if (this.isvalid !== true) {
                    isValid = false;
                }
            });

            if (isValid) {
                controlToValidate.removeClass(&quot;error&quot;);
            } else {
                controlToValidate.addClass(&quot;error&quot;);
            }
        });
});
</pre>
<p>And there you have it. Now when any validator on your form has the isValid property tripped to false on the client side, the CSS class of the offending control will be changed to “error”.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=75&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2009/01/31/set-the-css-class-of-aspnet-invalid-controls-using-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>
	</item>
		<item>
		<title>New release of Visual Studio 2008 XHTML 1.1 Templates available now</title>
		<link>http://damianedwards.wordpress.com/2008/10/06/new-release-of-visual-studio-2008-xhtml-11-templates-available-now/</link>
		<comments>http://damianedwards.wordpress.com/2008/10/06/new-release-of-visual-studio-2008-xhtml-11-templates-available-now/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 01:36:32 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/2008/10/06/new-release-of-visual-studio-2008-xhtml-11-templates-available-now/</guid>
		<description><![CDATA[I’ve uploaded a new release that now includes item templates for C# &#38; VB Web Application Projects and Web Site Projects. Plus, there is now a Project Template for creating C# Web Application Projects pre-configured to be XHTML 1.1 compliant, use a master page &#38; theme, and the CSS Friendly Control Adapters. It has some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=54&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’ve uploaded a <a href="http://www.codeplex.com/VSXHTML11Templates/Release/ProjectReleases.aspx?ReleaseId=17987">new release</a> that now includes item templates for C# &amp; VB Web Application Projects and Web Site Projects. Plus, there is now a <strong>Project Template</strong> for creating C# Web Application Projects pre-configured to be XHTML 1.1 compliant, use a master page &amp; theme, and the <a href="http://www.codeplex.com/cssfriendly">CSS Friendly Control Adapters</a>. It has some other goodies in it too (e.g. support for print specific CSS files in themes).</p>
<p><a href="http://www.codeplex.com/VSXHTML11Templates">http://www.codeplex.com/VSXHTML11Templates</a></p>
<p>Feedback always appreciated.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=54&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2008/10/06/new-release-of-visual-studio-2008-xhtml-11-templates-available-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>
	</item>
		<item>
		<title>Suggested improvements for CSS editor in Visual Web Developer and Expression Web</title>
		<link>http://damianedwards.wordpress.com/2008/05/21/suggested-improvements-for-css-editor-in-visual-web-developer-and-expression-web/</link>
		<comments>http://damianedwards.wordpress.com/2008/05/21/suggested-improvements-for-css-editor-in-visual-web-developer-and-expression-web/#comments</comments>
		<pubDate>Wed, 21 May 2008 06:20:00 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/2008/05/21/suggested-improvements-for-css-editor-in-visual-web-developer-and-expression-web/</guid>
		<description><![CDATA[People who know me will know that I love CSS and that I can often be found with my head deep in a CSS file in Visual Web Developer (the web tools in Visual Studio). Recently I&#8217;ve been thinking about how Microsoft could make the support for editing CSS files directly in these tools more [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=15&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>People who know me will know that I love CSS and that I can often be found with my head deep in a CSS file in Visual Web Developer (the web tools in Visual Studio). Recently I&#8217;ve been thinking about how Microsoft could make the support for editing CSS files directly in these tools more conducive to discovering features of CSS you don&#8217;t know about, improving productivity through better contextual awareness, and offering insight as to real world issues such as browser compatibilities.</p>
<p>So I&#8217;ve put together a <a href="http://files.damianedwards.com/VisualWebDeveloperImprovementSuggestions.pptx">series of mock-ups</a> that illustrate some of the ideas I have for improving the support for CSS file editing:</p>
<ul>
<li>Inline RGB colour picker</li>
<li>Ability to define colour swatches in XML comments including name, RGB and category</li>
<li>Inline colour swatch picker with $ keyboard shortcut that replaces name with hex RGB value on completion</li>
<li>Inline named colour picker with preview of named colour in pick list</li>
<li>Ability to choose browsers to warn of incompatibilities with when schema checking CSS</li>
<li>Green &#8220;squigglies&#8221; under CSS selectors and properties know to be unsupported or have issues in chosen warning browsers</li>
<li>ToolTips for CSS properties showing description and browser compatibility summary with hyperlinks to further information</li>
<li>ToolTips for CSS selectors showing description of what elements it will select, browser compatibility summary and specificity score with hyperlinks to further information on each</li>
<li>ToolTip preview of url resources (images) showing file size and image dimensions</li>
<li>ToolTip preview of font-family showing font source (TrueType, W3C, etc.) and font rendering preview</li>
<li>Support for automatic indenting of style declarations based on descendant or child selectors if they appear after each other</li>
</ul>
<p>Hopefully somebody on the <a href="http://blogs.msdn.com/expression/default.aspx">appropriate</a> <a href="http://blogs.msdn.com/webdevtools/default.aspx">teams</a> in Microsoft will here me <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/damianedwards.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/damianedwards.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=15&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2008/05/21/suggested-improvements-for-css-editor-in-visual-web-developer-and-expression-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET &amp; CSS: Using skins to &#8220;zero out&#8221; default style and set default CSS class names</title>
		<link>http://damianedwards.wordpress.com/2008/02/10/aspnet-css-using-skins-to-zero-out-default-style-and-set-default-css-class-names/</link>
		<comments>http://damianedwards.wordpress.com/2008/02/10/aspnet-css-using-skins-to-zero-out-default-style-and-set-default-css-class-names/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 01:28:34 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/?p=52</guid>
		<description><![CDATA[ASP.NET includes a feature called &#8220;Themes&#8221; that allows you to organise styling artifacts including CSS stylesheets and images into logical units that can be easily applied to a page or entire site through configuration. Part of this feature is the ability to create .skin files that set default values for certain properties of ASP.NET server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=52&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>ASP.NET includes a feature called &#8220;Themes&#8221; that allows you to organise styling artifacts including CSS stylesheets and images into logical units that can be easily applied to a page or entire site through configuration. Part of this feature is the ability to create .skin files that set default values for certain properties of ASP.NET server controls as part of a theme.</p>
<p>Not all properties of ASP.NET controls are skinnable. Indeed the initial intention of .skin files was to enable the setting of default values for properties such as FontColor and BorderWidth, which when serving to CSS supporting browsers ASP.NET will render as inline style attributes on the emitted HTML controls. So what place do they have when we apply all of our style rules via way of attached CSS stylesheets and selectors (the way we should)?</p>
<p>Despite their evil initial purpose we can put .skin files to good use for two purposes:</p>
<ol>
<li>Assigning CSS classes to all instances of particular ASP.NET server controls; and</li>
<li>Zeroing out the default inline style that ASP.NET sets on some controls.</li>
</ol>
<p>So how does this work?</p>
<p>In your theme folder add a new .skin file called Controls.skin:</p>
<p><a href="http://s511va.tuk.livefilestore.com/y1p8p3J9ORFPvTvOJRwhwGbd3kZme2gZ3ojMosxt04Q8arArcho8aPvLnYKvyFDYYp6r5TLkAJ5R8I?PARTNER=WRITER"><img style="border-width:0;" src="http://s511va.tuk.livefilestore.com/y1pc2epRtTqjlHe1pQIqWMM9x4mUM4_2PfhcRgupdJETY4RYDirmFGAirf7HPx7oJ8ziBPfABGBYO6ryPxkC-w34YoliqjfWym3?PARTNER=WRITER" border="0" alt="Add a skin file to your theme folder" width="671" height="490" /></a></p>
<p>Now we want to add some declarations to the file to:</p>
<ol>
<li>Zero out the inline style of the ASP.NET validator controls; and</li>
<li>Assign a default CSS class name to the Button, LinkButton, TextBox and validator controls.</li>
</ol>
<pre><span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">RequiredFieldValidator </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ForeColor</span><span style="color:blue;">="" </span><span style="color:red;">CssClass</span><span style="color:blue;">="validation-error" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">RangeValidator </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ForeColor</span><span style="color:blue;">="" </span><span style="color:red;">CssClass</span><span style="color:blue;">="validation-error" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">CompareValidator </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ForeColor</span><span style="color:blue;">="" </span><span style="color:red;">CssClass</span><span style="color:blue;">="validation-error" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">RegularExpressionValidator </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ForeColor</span><span style="color:blue;">="" </span><span style="color:red;">CssClass</span><span style="color:blue;">="validation-error" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">CustomValidator </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ForeColor</span><span style="color:blue;">="" </span><span style="color:red;">CssClass</span><span style="color:blue;">="validation-error" /&gt;

&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">LinkButton </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">CssClass</span><span style="color:blue;">="button" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">Button </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">CssClass</span><span style="color:blue;">="button" /&gt;
&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">TextBox </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">CssClass</span><span style="color:blue;">="text-box" /&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And that&#8217;s it! Now when ASP.NET renders these controls when they appear on a page (or in a site) with your theme configured, they&#8217;ll automatically pick up properties defined in this .skin file.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/damianedwards.wordpress.com/52/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/damianedwards.wordpress.com/52/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=52&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2008/02/10/aspnet-css-using-skins-to-zero-out-default-style-and-set-default-css-class-names/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>

		<media:content url="http://s511va.tuk.livefilestore.com/y1pc2epRtTqjlHe1pQIqWMM9x4mUM4_2PfhcRgupdJETY4RYDirmFGAirf7HPx7oJ8ziBPfABGBYO6ryPxkC-w34YoliqjfWym3?PARTNER=WRITER" medium="image">
			<media:title type="html">Add a skin file to your theme folder</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET &amp; CSS: Styling sortable columns in the GridView using CSS</title>
		<link>http://damianedwards.wordpress.com/2008/02/04/aspnet-css-styling-sortable-columns-in-the-gridview-using-css/</link>
		<comments>http://damianedwards.wordpress.com/2008/02/04/aspnet-css-styling-sortable-columns-in-the-gridview-using-css/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 06:05:00 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/2008/02/04/aspnet-css-styling-sortable-columns-in-the-gridview-using-css/</guid>
		<description><![CDATA[UPDATE: The modification to the CSS Friendly Control Adapters outlined in this article was recently applied to the CodePlex source code so you can now simply get the latest source code from CodePlex.
The following is an article describing one of the techniques I spoke about during my recent RDN topic, CSS Layout with ASP.NET &#38; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=8&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>UPDATE:</strong> The modification to the CSS Friendly Control Adapters outlined in this article was recently applied to the <a href="http://www.codeplex.com/cssfriendly/SourceControl/ListDownloadableCommits.aspx">CodePlex source code</a> so you can now simply get the latest source code from CodePlex.</p>
<p>The following is an article describing one of the techniques I spoke about during my recent <a href="http://www.readify.net/rdncalendar.aspx">RDN</a> topic, <a href="http://damianpedwards.spaces.live.com/blog/cns!A079DE667E1958B3!558.entry">CSS Layout with ASP.NET &amp; Visual Studio 2008</a>.</p>
<p>A common user interface requirement for applications is to visually indicate when:</p>
<ol>
<li>a column in a grid is sortable;</li>
<li>which column in a grid is currently the sort column; and</li>
<li>which direction the sort is being applied in (ascending or descending).</li>
</ol>
<p>In ASP.NET, we generally use the <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(VS.80).aspx">GridView</a> control to display tabular data and provide the user with the ability to <a href="http://msdn2.microsoft.com/en-us/library/01y1beh5(VS.80).aspx">sort</a> and <a href="http://msdn2.microsoft.com/en-us/library/7c4a91wd(VS.80).aspx">page</a> through that data. There are <a href="http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/#S5">many</a> <a href="http://dotnetjunkies.com/WebLog/thomasswilliams/archive/2005/11/09/133667.aspx">examples</a> <a href="http://geekswithblogs.net/ram/archive/2006/07/13/GridViewGenericSortImagesFunction.aspx">on</a> <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortexpression.aspx">the</a> <a href="http://blog.devexperience.net/en/2/Display_an_arrow_in_the_header_of_GridView.aspx">web</a> of techniques you can use to programmatically insert an image to indicate the currently sorted column and its sort direction (including the <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortexpression.aspx">MSDN documentation</a>). There are a number of problems with this approach:</p>
<ol>
<li>It mixes functional code with presentation logic. The code behind for our pages and user controls is complicated enough without having to trawl through formatting and layout logic;</li>
<li>It requires you to add this code on every GridView (or sub-class the GridView and use the new version instead); and</li>
<li>It dilutes the semantic meaning of the resultant HTML mark-up, thus affecting the page&#8217;s usability (IMG tags have no place in the header of a TABLE).</li>
</ol>
<p>So what&#8217;s a better solution I hear you say? The following solution uses ASP.NET, the <a href="http://www.codeplex.com/cssfriendly/">CSS Friendly Control Adapters</a> and CSS styling to:</p>
<ol>
<li>add sorting information to a GridView in a semantic and accessible fashion; and</li>
<li>apply visual effects relating to sorting behaviour.</li>
</ol>
<p>The <a href="http://www.codeplex.com/cssfriendly">CSS Friendly Control Adapters</a> alter the HTML mark-up produced by ASP.NET for many of the included server controls so that it is more accessible, standards compliant and, importantly, easier to style using CSS. You can grab the latest <a href="http://www.codeplex.com/cssfriendly/SourceControl/ListDownloadableCommits.aspx">source code</a> for the adapters from <a href="http://www.codeplex.com/">CodePlex</a> (be sure to download from the <a href="http://www.codeplex.com/cssfriendly/SourceControl/ListDownloadableCommits.aspx">source code section</a>, not the release section), however the technique shown here requires a small change to the included GridView adapter (further details about incorporating the CSS Friendly Control Adapters into your web project are included in the download). So, once you&#8217;ve downloaded the source, open up the solution and find the GridViewAdapter.cs file:</p>
<p><img style="border-width:0;" src="http://damianedwards.files.wordpress.com/2008/10/image.png?w=277&#038;h=432" border="0" alt="image" width="277" height="432" /></p>
<p>Replace its contents with <a href="http://files.damianedwards.com/CSSASPNETDepth/GridViewAdapter.zip">this modified version</a>. This adds a new function that sets the CSS class of the GridView&#8217;s header cells based on which column the GridView is currently sorted by. So for example if I have a GridView defined as such:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">GridView </span><span style="color:red;">ID</span><span style="color:blue;">="gvExample" </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">DataSourceID</span><span style="color:blue;">="pdsExample" </span><span style="color:red;">DataKeyNames</span><span style="color:blue;">="Id"
    </span><span style="color:red;">AllowPaging</span><span style="color:blue;">="true" </span><span style="color:red;">AllowSorting</span><span style="color:blue;">="true" </span><span style="color:red;">PageSize</span><span style="color:blue;">="10" </span><span style="color:red;">AutoGenerateColumns</span><span style="color:blue;">="false" </span><span style="color:red;">CssClass</span><span style="color:blue;">="customers-grid"&gt;
    &lt;</span><span style="color:#a31515;">Columns</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">BoundField </span><span style="color:red;">HeaderText</span><span style="color:blue;">="First Name" </span><span style="color:red;">DataField</span><span style="color:blue;">="FirstName" </span><span style="color:red;">SortExpression</span><span style="color:blue;">="FirstName"
            </span><span style="color:red;">HeaderStyle-CssClass</span><span style="color:blue;">="first-name" </span><span style="color:red;">ItemStyle-CssClass</span><span style="color:blue;">="first-name" /&gt;
        &lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">BoundField </span><span style="color:red;">HeaderText</span><span style="color:blue;">="Last Name" </span><span style="color:red;">DataField</span><span style="color:blue;">="LastName" </span><span style="color:red;">SortExpression</span><span style="color:blue;">="LastName"
            </span><span style="color:red;">HeaderStyle-CssClass</span><span style="color:blue;">="last-name" </span><span style="color:red;">ItemStyle-CssClass</span><span style="color:blue;">="last-name" /&gt;
        &lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">BoundField </span><span style="color:red;">HeaderText</span><span style="color:blue;">="Age" </span><span style="color:red;">DataField</span><span style="color:blue;">="Age" </span><span style="color:red;">SortExpression</span><span style="color:blue;">="Age"
            </span><span style="color:red;">HeaderStyle-CssClass</span><span style="color:blue;">="age" </span><span style="color:red;">ItemStyle-CssClass</span><span style="color:blue;">="age" /&gt;
        &lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">BoundField </span><span style="color:red;">HeaderText</span><span style="color:blue;">="Member for" </span><span style="color:red;">DataField</span><span style="color:blue;">="YearsAsMember" </span><span style="color:red;">SortExpression</span><span style="color:blue;">="YearsAsMember"
            </span><span style="color:red;">HeaderStyle-CssClass</span><span style="color:blue;">="years-as-member" </span><span style="color:red;">ItemStyle-CssClass</span><span style="color:blue;">="years-as-member" /&gt;
    &lt;/</span><span style="color:#a31515;">Columns</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">GridView</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Then when the GridView is rendered sorted by the First name column, the HTML mark-up emitted will look like this:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">div </span><span style="color:red;">class</span><span style="color:blue;">="AspNet-GridView" </span><span style="color:red;">id</span><span style="color:blue;">="ctl00_main_gvExample"&gt;
&lt;</span><span style="color:#a31515;">table </span><span style="color:red;">cellpadding</span><span style="color:blue;">="0" </span><span style="color:red;">cellspacing</span><span style="color:blue;">="0" </span><span style="color:red;">summary</span><span style="color:blue;">="" </span><span style="color:red;">class</span><span style="color:blue;">="customers-grid"&gt;
    &lt;</span><span style="color:#a31515;">thead</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">tr </span><span style="color:red;">class</span><span style="color:blue;">="AspNet-GridView-Header"&gt;
        &lt;</span><span style="color:#a31515;">th </span><span style="color:red;">class</span><span style="color:blue;">="sortable sorted asc first-name" </span><span style="color:red;">scope</span><span style="color:blue;">="col"&gt;
            &lt;</span><span style="color:#a31515;">a </span><span style="color:red;">href</span><span style="color:blue;">="javascript:__doPostBack('ctl00$main$gvExample','Sort$FirstName')"&gt;</span>First Name<span style="color:blue;">&lt;/</span><span style="color:#a31515;">a</span><span style="color:blue;">&gt;&lt;/</span><span style="color:#a31515;">th</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">th </span><span style="color:red;">class</span><span style="color:blue;">="sortable last-name" </span><span style="color:red;">scope</span><span style="color:blue;">="col"&gt;
            &lt;</span><span style="color:#a31515;">a </span><span style="color:red;">href</span><span style="color:blue;">="javascript:__doPostBack('ctl00$main$gvExample','Sort$LastName')"&gt;</span>Last Name<span style="color:blue;">&lt;/</span><span style="color:#a31515;">a</span><span style="color:blue;">&gt;&lt;/</span><span style="color:#a31515;">th</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">th </span><span style="color:red;">class</span><span style="color:blue;">="sortable age" </span><span style="color:red;">scope</span><span style="color:blue;">="col"&gt;
            &lt;</span><span style="color:#a31515;">a </span><span style="color:red;">href</span><span style="color:blue;">="javascript:__doPostBack('ctl00$main$gvExample','Sort$Age')"&gt;</span>Age<span style="color:blue;">&lt;/</span><span style="color:#a31515;">a</span><span style="color:blue;">&gt;&lt;/</span><span style="color:#a31515;">th</span><span style="color:blue;">&gt;
        &lt;</span><span style="color:#a31515;">th </span><span style="color:red;">class</span><span style="color:blue;">="sortable years-as-member" </span><span style="color:red;">scope</span><span style="color:blue;">="col"&gt;
            &lt;</span><span style="color:#a31515;">a </span><span style="color:red;">href</span><span style="color:blue;">="javascript:__doPostBack('ctl00$main$gvExample','Sort$YearsAsMember')"&gt;</span>Member for<span style="color:blue;">&lt;/</span><span style="color:#a31515;">a</span><span style="color:blue;">&gt;&lt;/</span><span style="color:#a31515;">th</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">tr</span><span style="color:blue;">&gt;
    &lt;/</span><span style="color:#a31515;">thead</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">tbody</span><span style="color:blue;">&gt;</span><span style="color:green;">&lt;!-- Data rows here --&gt;</span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">tbody</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">table</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">div</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Note how we now have CSS classes added to the &lt;th&gt; tags to describe their sorting behaviour (sortable, sorted and asc). We can see that all columns are sortable, and that the First Name column is currently being sorted by in the ascending direction. And because the logic to apply these classes is in the control adapter, it is automatically applied to all GridViews in the application.</p>
<p>There is a caveat to this approach however. The adapter relies on two properties of the GridView to determine the current sort column and direction: <a href="http://msdn2.microsoft.com/en-us/library/1sb8t4y0(VS.80).aspx">SortExpression</a> and <a href="http://msdn2.microsoft.com/en-us/library/zfs728sa(VS.80).aspx">SortDirection</a>. These are read only properties that are only populated when you provide data to the GridView by way of one of the <a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/default.aspx">data source controls</a> introduced in ASP.NET 2.0, e.g. <a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/objectdatasource.aspx">ObjectDataSource</a>, <a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/sqldatasource.aspx">SqlDataSource</a>, etc., and the <a href="http://msdn2.microsoft.com/en-us/library/hw694zdw(VS.80).aspx">DataSourceID</a> property. If you provide data to your GridView by setting its <a href="http://msdn2.microsoft.com/en-us/library/ay1s9at1(VS.80).aspx">DataSource</a> property directly from code behind (and calling <a href="http://msdn2.microsoft.com/en-us/library/kdzx4e13(VS.80).aspx">DataBind()</a>) the sort properties are not set and thus the adapter cannot insert the required CSS class names. You must also initially call the <a href="http://msdn2.microsoft.com/en-us/library/ms155982(VS.80).aspx">Sort()</a> method on the GridView from the Page_Load() method in order to force the setting of these properties the first time the page is rendered:</p>
<pre class="code"><span style="color:blue;">protected void </span>Page_Load(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">EventArgs </span>e)
{
    <span style="color:blue;">if </span>(!IsPostBack)
    {
        <span style="color:green;">// Set default sort expression
        </span>gvExample.Sort(<span style="color:#a31515;">"FirstName"</span>, <span style="color:#2b91af;">SortDirection</span>.Ascending);
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If you are not using the data source controls (the ObjectDataSource in particular) I thoroughly recommended you take a look as they provide you with &#8220;free&#8221; sorting and paging functionality out of the box without the need to manually handle events on the GridView. If you don&#8217;t like the way the ObjectDataSource requires a separate business logic class to provide its data access functionality, for instance if you are implementing a MVP pattern in the &#8220;<a href="http://www.martinfowler.com/eaaDev/PassiveScreen.html">Passive View</a>&#8221; flavour, then you can sub-class the OjectDataSource and force it to look on the instance of the class for the hosting page (or user control) for its methods instead (this is the method I used in the RDN sample solution and I will post an article on this technique shortly).</p>
<p>Now that we have our CSS classes set we can attach some CSS rules that provide some visual indicators on the sorting behaviour. The following CSS rules do just that (I&#8217;ve placed these in a common Grid.css file in the sample project):</p>
<pre class="code"><span style="color:#a31515;">div.AspNet-GridView </span>{
    <span style="color:red;">border</span>: <span style="color:blue;">1px solid #828790</span>;
    <span style="color:red;">font-size</span>: <span style="color:blue;">0.8em</span>;
    <span style="color:red;">min-height</span>: <span style="color:blue;">1px</span>;
    <span style="color:red;">font-family</span>: <span style="color:blue;">"Lucida Sans"</span>;
}

    <span style="color:#a31515;">div.AspNet-GridView table </span>{
        <span style="color:red;">width</span>: <span style="color:blue;">100%</span>;
        <span style="color:red;">border-collapse</span>: <span style="color:blue;">collapse</span>;
    }    

        <span style="color:#a31515;">div.AspNet-GridView table thead tr th </span>{
            <span style="color:red;">padding</span>: <span style="color:blue;">3px 3px 2px 2px</span>;
            <span style="color:red;">background</span>: <span style="color:blue;">url('grid-header-back.gif') top left repeat-x</span>;
            <span style="color:red;">font-weight</span>: <span style="color:blue;">normal</span>;
            <span style="color:red;">border-bottom</span>: <span style="color:blue;">1px solid #d5d5d5</span>;
            <span style="color:red;">border-right</span>: <span style="color:blue;">1px solid #e3e4e6</span>;

        }
            <span style="color:#a31515;">div.AspNet-GridView table thead tr th.sortable </span>{
                <span style="color:red;">padding</span>: <span style="color:blue;">0px</span>;
            }
                <span style="color:#a31515;">div.AspNet-GridView table thead tr th.sortable:hover </span>{
                    <span style="color:red;">background</span>: <span style="color:blue;">#b7e7fb url('grid-header-sortable-back-hover.gif') top left repeat-x</span>;
                    <span style="color:red;">border</span>: <span style="color:blue;">1px solid #96d9f9</span>;
                    <span style="color:red;">border-top</span>: <span style="color:blue;">none</span>;
                    <span style="color:red;">border-left</span>: <span style="color:blue;">none</span>;
                }

                <span style="color:#a31515;">div.AspNet-GridView table thead tr th.sortable a </span>{
                    <span style="color:red;">display</span>: <span style="color:blue;">block</span>;
                    <span style="color:red;">padding</span>: <span style="color:blue;">3px 3px 2px 2px</span>;
                    <span style="color:red;">color</span>: <span style="color:blue;">Black</span>;
                    <span style="color:red;">min-height</span>: <span style="color:blue;">1px</span>; <span style="color:green;">/* Force layout in IE7 to prevent rendering issues */
                </span>}
                    <span style="color:#a31515;">div.AspNet-GridView table thead tr th.sortable a:hover </span>{
                        <span style="color:red;">text-decoration</span>: <span style="color:blue;">none</span>;
                    }

            <span style="color:#a31515;">div.AspNet-GridView table thead tr th.sorted </span>{
                <span style="color:red;">background</span>: <span style="color:blue;">#d8ecf6 url('grid-header-sorted-back.gif') top left repeat-x</span>;
                <span style="color:red;">border</span>: <span style="color:blue;">1px solid #96d9f9</span>;
                <span style="color:red;">border-top</span>: <span style="color:blue;">none</span>;
                <span style="color:red;">border-left</span>: <span style="color:blue;">none</span>;
            }

                <span style="color:#a31515;">div.AspNet-GridView table thead tr th.asc a </span>{
                    <span style="color:red;">background</span>: <span style="color:blue;">transparent url('grid-header-asc-glyph.gif') center 1px no-repeat</span>;
                }

                <span style="color:#a31515;">div.AspNet-GridView table thead tr th.desc a </span>{
                    <span style="color:red;">background</span>: <span style="color:blue;">transparent url('grid-header-desc-glyph.gif') center 1px no-repeat</span>;
                }

        <span style="color:#a31515;">div.AspNet-GridView table tbody tr td </span>{
            <span style="color:red;">padding</span>: <span style="color:blue;">2px 6px 2px 4px</span>;
            <span style="color:red;">border</span>: <span style="color:blue;">1px solid #efefef</span>;
        }

        <span style="color:#a31515;">div.AspNet-GridView table thead tr th.action</span>,
        <span style="color:#a31515;">div.AspNet-GridView table tbody tr td.action </span>{

            <span style="color:red;">border-left</span>: <span style="color:blue;">none</span>;
            <span style="color:red;">border-right</span>: <span style="color:blue;">none</span>;
        }
        <span style="color:#a31515;">div.AspNet-GridView table tbody tr td.action </span>{
            <span style="color:red;">padding</span>: <span style="color:blue;">2px 2px 2px 2px</span>;
            <span style="color:red;">width</span>: <span style="color:blue;">40px</span>;
            <span style="color:red;">text-align</span>: <span style="color:blue;">center</span>;
        }

    <span style="color:#a31515;">div.AspNet-GridView table tbody tr.AspNet-GridView-Alternate td </span>{
        <span style="color:red;">background</span>: <span style="color:blue;">#f2f9fc</span>;
    }

    <span style="color:#a31515;">div.AspNet-GridView-Pagination </span>{
        <span style="color:red;">background</span>: <span style="color:blue;">#e6e9ee</span>;
        <span style="color:red;">text-align</span>: <span style="color:blue;">center</span>;
        <span style="color:red;">padding</span>: <span style="color:blue;">2px 3px 2px 3px</span>;
        <span style="color:red;">font-size</span>: <span style="color:blue;">0.9em</span>;
        <span style="color:red;">min-height</span>: <span style="color:blue;">1px</span>; <span style="color:green;">/* Force layout in IE7 to prevent rendering issues */
    </span>}
        <span style="color:#a31515;">div.AspNet-GridView-Pagination span </span>{
            <span style="color:red;">padding</span>: <span style="color:blue;">0px 3px</span>;
            <span style="color:red;">background</span>: <span style="color:blue;">#d8ecf6</span>;
            <span style="color:red;">border</span>: <span style="color:blue;">1px solid #96d9f9</span>;
        }

<span style="color:#a31515;">div.grid-row-count </span>{
    <span style="color:red;">color</span>: <span style="color:blue;">#666666</span>;
    <span style="color:red;">padding</span>: <span style="color:blue;">2px 0px 2px 6px</span>;
    <span style="color:red;">font-size</span>: <span style="color:blue;">0.8em</span>;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>These style rules use a small number of background images to give our GridView a nice Vista-like look:</p>
<p><img src="http://damianedwards.files.wordpress.com/2008/10/image1.png?w=618&#038;h=249" border="0" alt="image" width="618" height="249" /></p>
<p>You can immediately see that the First Name column is currently the sort column in the ascending direction. Hovering over other sortable columns provides feedback by way of a :hover background image, here I&#8217;ve hovered my mouse over the Last Name column:</p>
<p><img style="border-width:0;" src="http://damianedwards.files.wordpress.com/2008/10/image2.png?w=617&#038;h=250" border="0" alt="image" width="617" height="250" /></p>
<p>I&#8217;ve also added some formatting to the pager section of the GridView to highlight the current page.</p>
<p>To apply styles that are specific to this particular GridView, e.g. column widths, we can add some style rules like thus:</p>
<pre class="code"><span style="color:#a31515;">table.customers-grid </span>{

}

    <span style="color:#a31515;">table.customers-grid th.first-name</span>,
    <span style="color:#a31515;">table.customers-grid td.first-name </span>{
        <span style="color:red;">width</span>: <span style="color:blue;">35%</span>;    }

    <span style="color:#a31515;">table.customers-grid th.last-name</span>,
    <span style="color:#a31515;">table.customers-grid td.last-name </span>{

    }

    <span style="color:#a31515;">table.customers-grid th.age</span>,
    <span style="color:#a31515;">table.customers-grid td.age </span>{
        <span style="color:red;">text-align</span>: <span style="color:blue;">center</span>;
        <span style="color:red;">width</span>: <span style="color:blue;">10%</span>;
    }

    <span style="color:#a31515;">table.customers-grid th.years-as-member</span>,
    <span style="color:#a31515;">table.customers-grid td.years-as-member </span>{
        <span style="color:red;">width</span>: <span style="color:blue;">15%</span>;
        <span style="color:red;">text-align</span>: <span style="color:blue;">center</span>;
    }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><em>Note: I&#8217;ve tested the included CSS here with IE7 and Firefox. There is a small issue with the Firefox rendering which I haven&#8217;t bothered to fix (the left-most border is not displayed due to the different ways IE7 and Firefox collapse borders) and you will definitely need to make some changes to properly support IE6 (e.g. adding support for the :hover pseudo class on elements other than &lt;a&gt; using an .htc file) but they are outside the scope of this article.</em></p>
<p>So there you have it. Using this method we have freed our code-behind of nasty image injection code and made our GridViews more accessible and stylable to boot.</p>
<p><a href="http://files.damianedwards.com/CSSASPNETDepth/RDN%20-%20CSS%20ReadiDepth.zip">Download the sample project for this article here</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/damianedwards.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/damianedwards.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=8&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2008/02/04/aspnet-css-styling-sortable-columns-in-the-gridview-using-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>

		<media:content url="http://damianedwards.files.wordpress.com/2008/10/image.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://damianedwards.files.wordpress.com/2008/10/image1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://damianedwards.files.wordpress.com/2008/10/image2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Internet Explorer 6 to render transparent PNGs with minimal fuss</title>
		<link>http://damianedwards.wordpress.com/2007/03/29/getting-internet-explorer-6-to-render-transparent-pngs-with-minimal-fuss/</link>
		<comments>http://damianedwards.wordpress.com/2007/03/29/getting-internet-explorer-6-to-render-transparent-pngs-with-minimal-fuss/#comments</comments>
		<pubDate>Thu, 29 Mar 2007 06:59:00 +0000</pubDate>
		<dc:creator>Damian Edwards</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://damianedwards.wordpress.com/?p=37</guid>
		<description><![CDATA[So you&#8217;re creating a great looking website and embracing the latest techniques like transparent PNG images to get good looking effects. Everything looks great in IE7 and Firefox but then you fire it up in IE6. Oh no!! What are all these gray backgrounds in my transparent PNGs? Well IE6 doesn&#8217;t support transparent PNGs as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=37&subd=damianedwards&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So you&#8217;re creating a great looking website and embracing the latest techniques like transparent PNG images to get good looking effects. Everything looks great in IE7 and Firefox but then you fire it up in IE6. Oh no!! What are all these gray backgrounds in my transparent PNGs? Well IE6 doesn&#8217;t support transparent PNGs as simply as other browsers <strong>but it does support them</strong> with a little tweaking.</p>
<p>You can make IE6 render transparent PNGs just fine using the a combination of two of IE&#8217;s proprietary features: <a href="http://msdn2.microsoft.com/en-us/library/ms532849.aspx">DirectX Filters</a> and <a href="http://msdn2.microsoft.com/en-us/library/ms531078.aspx">DHTML Behaviors</a>. Filters allow IE to apply all types of visual effects to HTML, pretty pointless usually when creating &#8220;standards&#8221; compliant websites but one filter in particular is useful in our situation; <a href="http://msdn2.microsoft.com/en-us/library/ms532969.aspx">AlphaImageLoader</a>. This filter will load an image, including a transparent PNG, into the element between the background and the content and even resize the element to fit the image in (there are other options to clip the image but we want the default behaviour). Great, now all we need is a way to do this easily for any PNG image in our site, and only in IE6. That&#8217;s where DHTML Behaviors come in.</p>
<p>A behavior is basically a javascript file that encapsulates DHTML manipulating code so that it can be re-used. You can attach to any event on the element the behavior is applied to and run the script when the event is fired. The really good bit is that DHTML Behaviors are applied by CSS rules so we can include them in our standard site stylesheet. Perfect!</p>
<p>Create a blank transparent GIF image 16 x 16 pixels in size and call it blank.gif and place it in the Images folder of your website.</p>
<p>Then create a file in your website called PNGImage.htc and paste the following code into it (or get it from the link at end of this post):</p>
<pre>&lt;public:attach onevent="RenderPNG();" event="oncontentready"&gt; &lt;script language="javascript" type="text/javascript"&gt; function RenderPNG() { var img = element; var src; // check that behavior hasn't already been applied if (img.tagName.toLowerCase() == "img" &amp;&amp; img.style.filter.indexOf("AlphaImageLoader") &lt; 0 &amp;&amp; img.src.toLowerCase().indexOf(".png") &gt; 0) { src = img.src; img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + src + "\')"; img.src = "Images/blank.gif"; } } &lt;/script&gt;</pre>
<p>This behavior will be attached to our IMG tags. As you can see the behavior attaches to the element&#8217;s oncontentready event. When the event is raised once the element is ready for scripting, the behavior check&#8217;s to see if it has already been applied to this element, and if not, applies the filter and sets the element&#8217;s src property to a transparent gif file. This way the IMG tag still contains a vaild image so will honour its normal rendering duties but now has the transparent PNG image loaded into it behind the transparent GIF.</p>
<p>Now, in your site&#8217;s stylesheet file add this class descriptor:</p>
<pre>IMG.PNGImage { _behavior: url('PNGImage.htc'); /* IE6 Only */ }</pre>
<p>This will cause the behavior to be loaded for any IMG tag with its class set to include PNGImage. The underscore at the beginning of the behavior property makes it invisible to IE7 which ignores CSS properties prefixed with underscores, as will all other browsers. Make sure the path to the .htc file is relative to the page the class is applied to, not the CSS file itself which is usually the case for urls in stylesheets, such as for loading background images.</p>
<p>Now in your HTML assign the PNGImage class to any IMG tag with a PNG file:</p>
<pre>&lt;img alt="A transparent icon" src="Images/my-icon.png" class="PNGImage" /&gt;</pre>
<p>And that&#8217;s it! If you wanted to, you could attach the behavior directly to the IMG element via an element descriptor in your stylesheet, saving you adding the class to each IMG tag, but this will obviously result in a few more CPU cycles being chewed up on the client in IE6 when loading pages:</p>
<pre>IMG { _behavior: url('PNGImage.htc'); /* IE6 Only */ }</pre>
<p>Files:</p>
<ul>
<li><a href="http://files.tilda.biz/ajax-css-tricks/PNGImage.htc">PNGImage.htc</a></li>
<li><a href="http://files.tilda.biz/ajax-css-tricks/blank.gif">blank.gif</a></li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/damianedwards.wordpress.com/37/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/damianedwards.wordpress.com/37/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/damianedwards.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/damianedwards.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/damianedwards.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/damianedwards.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/damianedwards.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/damianedwards.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/damianedwards.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/damianedwards.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/damianedwards.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/damianedwards.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=damianedwards.wordpress.com&blog=4827226&post=37&subd=damianedwards&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://damianedwards.wordpress.com/2007/03/29/getting-internet-explorer-6-to-render-transparent-pngs-with-minimal-fuss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">damianedwards</media:title>
		</media:content>
	</item>
	</channel>
</rss>