Date format strings not being applied?

  • Thread starter Thread starter Alec MacLean
  • Start date Start date
A

Alec MacLean

Hi,

Tools and target: VS2005 Pro, SQL server 2000, ASP.NET (GridView).

I am trying to get a date field inside a GridView to display without the
time element.

The date field is coming from a SQL DateTime column.

I have set the
<asp:BoundField DataField="DateClose" DataFormatString="{0:dd/MM/yyyy}"
HeaderText="Close Date" />

I have also tried {0:d} and {0:D} as alternative formats. None seem to
work.

The date is coming out with the time element included, e.g. "01/12/2006
00:00:00", each time.

Any one got an idea why the format string isn't working in this case?

Thanks

Al
 
hi alec.
for some bizarre reason, you have to set HtmlEncode=false on a bound column
in a gridview, to get the DataFormatString to work. loads of people have
complained about this.
hope this helps
Tim
 
indeed! i posted this solution on my blog last year and it is by far the
most visited article.
cheers
 
Back
Top