Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Formatting dates in the GridView

Reply
Thread Tools

Formatting dates in the GridView

 
 
thechaosengine
Guest
Posts: n/a
 
      02-07-2006
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


 
Reply With Quote
 
 
 
 
Rick
Guest
Posts: n/a
 
      02-07-2006
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")

"thechaosengine" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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
>
>



 
Reply With Quote
 
 
 
 
S. Justin Gengo [MCP]
Guest
Posts: n/a
 
      02-07-2006
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
"thechaosengine" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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
>
>



 
Reply With Quote
 
thechaosengine
Guest
Posts: n/a
 
      02-07-2006
Thanks guys!

Thast a great help



Simon


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RFC-822 dates into Ruby dates kellygreer1 Ruby 1 06-08-2008 10:59 PM
Need to use dates earlier than 1900 (Time library says out of range for dates < 1900) me@benjaminarai.com Ruby 1 07-17-2007 02:25 PM
FAQ Dates; Opera Dates. Dr J R Stockton Javascript 0 06-18-2007 03:51 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments