Solved

ASP.net change format of column in GridView at runtime

Posted on 2011-03-01
2
677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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 …
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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