Need to have ShortDateTime Format with Datetime Type in DataGrid

Discussion in 'ASP .Net Web Controls' started by A Programmer, Oct 7, 2005.

  1. A Programmer

    A Programmer Guest

    I can't believe I have never run into this before but, I have an object that
    has a property of type DateTime. A collection of these objects are used to
    populate my DataGrid. In DateTime format they display the date AND the time,
    I don't need nor want the time just the date. If I format at any point to a
    ShortDate I have to convert the type to a string which when applied to the
    grid interferes with sorting.
    Is there any way to keep the datatype as DateTime but display only Date?
     
    A Programmer, Oct 7, 2005
    #1
    1. Advertising

  2. A Programmer

    Alex S Moore Guest

    "A Programmer" wrote:

    > Is there any way to keep the datatype as DateTime but display only Date?


    If you are binding with DataBinder.Eval, try something like this:
    Text='<%# DataBinder.Eval(Container.DataItem, "CallDate", "{0:d}") %>'

    The third parameter specifies format, like '10/07/2005' for US format in my
    example.

    Alex
     
    Alex S Moore, Oct 7, 2005
    #2
    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. luna
    Replies:
    1
    Views:
    6,856
  2. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    743
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  3. Tim Peters
    Replies:
    0
    Views:
    580
    Tim Peters
    Sep 9, 2003
  4. mp
    Replies:
    1
    Views:
    417
    John Machin
    Jul 28, 2006
  5. Martin
    Replies:
    0
    Views:
    363
    Martin
    Dec 27, 2008
Loading...

Share This Page