Formatting dates in the GridView

T

thechaosengine

Hi all,

I'm having trouble getting dates to display in the right format in my GridView.

I'd like it to appear in the UK format - just the date, not the time, but
I'm not having any luck.

Someone suggested i try DataFormatString="{0:dd-mm-yyyy}" on the appropriate
column however that still outputs 24/04/2006 00:00:00

Can anyone suggest how to get rid of the time element?

Many thanks all

Simon
 
R

Rick

The DataFormatString will only work for a BoundColumn. If you are using a
TemplateColumn you can use:

DataBinder.Eval(Container.DataItem, "mydate", "dd-mm-yyyy")
 
S

S. Justin Gengo [MCP]

Simon,

You have to disable the HtmlEncoding of the column, which is set to true by
default.

Here's an example of a price column I wanted to format as currency with no
decimal. The format won't be used unless HtmlEncode is set to "False".
<asp:BoundField DataField="Price" DataFormatString="{0:c0}"
HtmlEncode="False" HeaderText="Price" SortExpression="Price" />


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top