Formatting dates in the GridView

Discussion in 'ASP .Net' started by thechaosengine, Feb 7, 2006.

  1. 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
    thechaosengine, Feb 7, 2006
    #1
    1. Advertising

  2. thechaosengine

    Rick Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Rick, Feb 7, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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
    >
    >
    S. Justin Gengo [MCP], Feb 7, 2006
    #3
  4. Thanks guys!

    Thast a great help

    :)

    Simon
    thechaosengine, Feb 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    859
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    189
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    202
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    187
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    155
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page