How to display shortdate format on a datagrid?

Discussion in 'ASP .Net Datagrid Control' started by irene, Oct 27, 2004.

  1. irene

    irene Guest

    Hi, I am displaying a datagrid on my webpage and it is linking to a
    dataset. There is a datetime value from the dataset showing on the
    webpage(datagrid) as full date format, like "10/27/2004 12:00:00 AM".
    How can I convert them to shortdate format '10/27/2004'? Before I was
    using sth like:

    <asp:TemplateColumn HeaderText="Course Start Date">
    <ItemTemplate>
    <asp:Label text = '<%#
    DateTime.Parse(Container.dataItem("CD_Date")).toString("D") %>' ID =
    "lblStartDate" Runat =server/>
    </ItemTemplate>
    </asp:TemplateColumn>

    But now I wonder whether there is an easy way to do it other than that
    because the datagrid is linking to a dataset directly and I dont need
    to add those Itemtemplate anymore.

    Can anyone help me?

    Thanks.

    Irene
     
    irene, Oct 27, 2004
    #1
    1. Advertising

  2. Irene, you can just use a BoundColumn with its DataFormatString set to
    {0:d}. You can see an example here:
    http://datawebcontrols.com/faqs/CustomizingAppearance/FormatDateTimeData.shtml

    hth


    irene wrote:
    > Hi, I am displaying a datagrid on my webpage and it is linking to a
    > dataset. There is a datetime value from the dataset showing on the
    > webpage(datagrid) as full date format, like "10/27/2004 12:00:00 AM".
    > How can I convert them to shortdate format '10/27/2004'? Before I was
    > using sth like:
    >
    > <asp:TemplateColumn HeaderText="Course Start Date">
    > <ItemTemplate>
    > <asp:Label text = '<%#
    > DateTime.Parse(Container.dataItem("CD_Date")).toString("D") %>' ID =
    > "lblStartDate" Runat =server/>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > But now I wonder whether there is an easy way to do it other than that
    > because the datagrid is linking to a dataset directly and I dont need
    > to add those Itemtemplate anymore.
    >
    > Can anyone help me?
    >
    > Thanks.
    >
    > Irene



    --

    Scott Mitchell

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Oct 27, 2004
    #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. Brian Candy
    Replies:
    2
    Views:
    1,205
    Janaka
    Feb 18, 2004
  2. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    546
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  3. Brian K. Williams
    Replies:
    0
    Views:
    561
    Brian K. Williams
    Mar 2, 2004
  4. Jim Florence
    Replies:
    3
    Views:
    6,842
    Ken Cox [Microsoft MVP]
    Jun 25, 2006
  5. Paul D. Fox

    Display a Datagrid & Export a Datagrid to Excel

    Paul D. Fox, Jul 21, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    237
    Elton Wang
    Jul 21, 2005
Loading...

Share This Page