Saturday, August 18, 2007

Date Column format works with DataGrid, but not with GridView

When displaying a date column in a gridview, it is often the case that you only need to display the date and not the time. This is simple enough, just include a DataFormatString attribute in your BoundField declaration. Easy huh?



Let's see the results:
10/11/2006 2:07:35 PM

11/1/2005 1:52:11 PM

5/28/2005 12:28:01 PM

Wha???? For the DataFormatString to correctly display, you have to include an HtmlEncode="false" attribute in your column declaration as well. So your code should look something like this:


And the world is a better place:

10/11/2006

11/1/2005

5/28/2005