Solved

ASP.net change format of column in GridView at runtime

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save ms data to server side. 19 56
RLDC Reporting in Visual studio 11 31
using CK editor in iframes 5 18
Data organization issue 7 21
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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