Date format strings not being applied?

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
 
T

Tim_Mac

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
 
T

Tim_Mac

indeed! i posted this solution on my blog last year and it is by far the
most visited article.
cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top