Solved

ASP.net change format of column in GridView at runtime

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

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

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

17 Experts available now in Live!

Get 1:1 Help Now