views:

289

answers:

3

I have a web application that I am working on(ASP.NET 2.0 & C#). In it, I have a gridview that gets data from an Oracle Database. Some of the data that I need to display is dates. But when the dates in my gridview show like this:

2009-04-02 00:00:00

I'd prefer they show without the time. I'm using the codebehind to get the data, so I cant alter the fields of the gridview manually. This is all the code for my gridview :

<asp:GridView ID="Grid" runat="server" EmptyDataText="There are no data records to display." ></asp:GridView>

How do I stop the time from displaying?

+3  A: 

You can apply a dataformatstring in the gridview column to only show the date.

To get it to work you must make sure that HTMLEncode is set to false.

More information

TheTXI
+3  A: 

if you set your datasource programmatically (code behind), you can still have all your columns in the gridview (use asp:DataBoundColumn)

DataFormatString="{0:d}"

EDIT

this code is for your aspx page, if you really want to stick your presentation logic in your code behind - you have 2 options:

  1. format the Date on "RowDataBound" event
  2. format the Date in your query - that way you won't have to deal with formatting in code at all
roman m
How can I use this in my codebehind?
zohair
A: 

You can use DataFormatString="{0:d}" HtmlEncode="False"

do not forget to use the last section [htmlencode]

I hope this works ... this works for me !!!!

Arunendra