Gridview date format!!!!

Posted on 2006-06-03
Last Modified: 2012-06-27
I am using gridview to display dates from a datetime filed in a sql server 2005 database. The gridview dislpays the full date with the time. I want to trim off the time and display the date only. I have read up on how to do this, but it is not working for some reason.

In the gridview properties, it has a dataformatstring property. I am trying to use the "{0:d}" format string for short date. I even went into the source and hard coded DataFormatString="{0:d}".

The gridview seems to ignore any formatting I attempt to use.

Any help would be greatly appreciated.
Question by:phil301
    LVL 96

    Assisted Solution

    by:Bob Learned
    Try this:



    Author Comment

    That doesnt seem to work either. I get no response from the field. I know its the right field, I can leave off the bracket and it will error out. Any other suggestions?
    LVL 27

    Accepted Solution

    use this
    <asp:boundfield datafield="datecolum" dataformatstring="{0:MM/dd/yy}" htmlencode="false" />
    without the htmlencode attribute set to false you will get the time added as well


    Author Comment

    You da man!!!! htmlencode = "False" did the trick.
    LVL 27

    Expert Comment

    Glad it worked for you

    Good luck
    LVL 2

    Expert Comment

    here is a cool post I found that shows you how to do it so that you do it and apply the change to all dates using the Culture info.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now