Solved VB format bound date column after load in GridView

Posted on 2011-05-11
Last Modified: 2012-05-11

In 4 I use a connection string to load a GridView. What VB code would I use to format a date column called "MyDate" to show only the date and not the time after load
Question by:murbro
    LVL 16

    Expert Comment

    by:Imran Javed Zia
    in column specify DataFormatString as following
    <asp:BoundField DataFormatString="{0:MM/dd/yyy}"

    Author Comment

    The GridView is populated with a connection string. I need VB code to do this afterwards
    LVL 14

    Accepted Solution

    in row Databound event of your gridview

    add the folowing code

     If e.Row.RowType = DataControlRowType.DataRow Then
                    Dim ds As DateTime = DateTime.Parse(e.Row.Cells(UR CELL NUMBER).Text)
                    e.Row.Cells.Item(UR CELL NUMBER).Text = ds.ToString("dd/MM/yyyy")
      End If

    Open in new window

    replace URCELL NUMBER with the actual cell number in which u will be having the date column

    Author Closing Comment

    thanks. Sorry about late reply
    LVL 14

    Expert Comment

    you are welcome !. Happy about ur pbm solved..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    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…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now