Solved

ASP.net change format of column in GridView at runtime

Posted on 2011-03-01
2
674 Views
Last Modified: 2012-05-11
Hi

I have a GridView in ASP.net 4 that pulls data from a SQL Server 2008 Table whose structure is shown in the imagke below.  The [Start date] and [End date] columns that are formatted as date show both the date and the time (12:00:00).
What VB code would I use to reformat these two columns to show the date only.
Thanks
 table
0
Comment
Question by:murbro
2 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35010000
Hi,

I don't think you can change the Format of the Column by code, but you can change the format of the cells of that column using the RowDataBound event, here is an example assuming that your StartDate field is in the second Column of you gridview

Hope it helps
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim dr As DataRowView
            Dim dtDate As DateTime

            dr = e.Row.DataItem
            dtDate = DateTime.Parse(dr("StartDate").ToString)
            e.Row.Cells(1).Text = dtDate.ToString("MM-dd-yyyy")

        End If

    End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 35085642
thanks very much. Apologies for late reply
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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