[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

ASP.net VB format bound date column after load in GridView

Hi

In ASP.net 4 I use a connection string to load a GridView. What VB code would I use to format a date column called "MyDate" to show only the date and not the time after load
0
Murray Brown
Asked:
Murray Brown
  • 2
  • 2
1 Solution
 
Imran Javed ZiaCommented:
in column specify DataFormatString as following
<asp:BoundField DataFormatString="{0:MM/dd/yyy}"
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
The GridView is populated with a connection string. I need VB code to do this afterwards
0
 
dejaanbuCommented:
in row Databound event of your gridview

add the folowing code

 If e.Row.RowType = DataControlRowType.DataRow Then
                Dim ds As DateTime = DateTime.Parse(e.Row.Cells(UR CELL NUMBER).Text)
                e.Row.Cells.Item(UR CELL NUMBER).Text = ds.ToString("dd/MM/yyyy")
  End If

Open in new window


replace URCELL NUMBER with the actual cell number in which u will be having the date column
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks. Sorry about late reply
0
 
dejaanbuCommented:
you are welcome !. Happy about ur pbm solved..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now