Solved

ASP.net change format of column in GridView at runtime

Posted on 2011-03-01
2
673 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
grab and show facebook pages event calendars 6 64
Align Buttons next to each other 2 25
What .NET website keeps me current? 9 54
Jquery autocomplete 10 68
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

13 Experts available now in Live!

Get 1:1 Help Now