Thursday, September 21, 2006
« Windows Forms Controls Extender - DataGr... | Main | Holy Cow, I'm White and Nerdy! »

I tend to shy away from Grid-based controls, generally favoring the Repeater-style controls when performing ASP.NET databinding; usually because I get more flexibility in the layout of the Repeater-style controls, not because I don't like grids.  Grids, like most everything have their place.

I was doing some databinding on an small ASP.NET application wherein I was using a GridView control and needed to format a date column.  I was setting the DataFormatString property to the format I desired (i.e. {0:MM/dd/yyyy}), but was dismayed that the date format wasn't taking effect.

The problem is easily resolved by setting the HtmlEncode property of the BoundField to false, thereby not encoding the column to HTML text before being formatted.

<asp:boundfield datafield="DeliveryDate" dataformatstring="{0:MM/dd/yyyy}" htmlencode="false" headertext="Delivery Date" />

Simple.

Thursday, September 21, 2006 2:02:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [8]  |  Trackback