tags:

views:

36

answers:

1

The MySQL database has a date field in this format:

yyyy-mm-dd (2009-12-01)

When this field is pulled into a Gridview the format changes to:

yyyy-mm-dd HH:mm (2009-12-01 12:00)

How do I get the gridview not to change the default database format?

(most solutions that I have found recommend setting the value in asp:boundfield but this requires the potentially risky HtmlEncode=false)

A: 

I don't think that it would be risky to set HtmlEncode = false on date/time field. It's unlikely that any sql injection attack could inject potentially harmful script into a datetime value.

It sounds like the solutions you've found probably refer to setting the DataFormatString and setting HtmlEncode = false. I would go with one of the solutions you've already found.

Or as found here: http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/

David Stratton
Thanks. This works well when manually defining columns - but not when the gridview is bound to a sql data source. It results in duplicate columns (ie the manually defined one, and the automatically bound one).
John M