Formatting my date in the GridView :-(

S

Simon Harvey

Hi all,

I'm having problems getting my date to format. Someone told me that with
the GridView, you need to use a TemplateColumn and not a BoundColumn when
displaying dates.

Given that, can anyone see what the problem is with the following code....

<asp:TemplateField HeaderText="Departure Date">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DepartDate",
"{0:dd-mm-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

When it comes to rendering, the grid continues to display the full date and
time. It's as though it's just ignoring the date formatting instruction.

Can anyone tell me why.

I'd be very grateful if anyone could help

Thanks

Simon
 
T

Terry Burns

You dont need template columns to format a bound date column.

<asp:BoundColumn DataField="FirstPublished" HeaderText="Published"
DataFormatString="{0:dd/MM/yyyy}">
</asp:BoundColumn>

HTH

Terry Burns
http://TrainingOn.net
 
S

Simon Harvey

Hi Guys

I am using the GridView control and I've tried doing the html encoding thing
as well. I'm a bit stuck now because I can't get either version to work.

I must be doing something stupid or my setup is different to everyone elses
or something. Not sure what it is though :-(

Thanks for your help though

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top