Formatting my date in the GridView :-(

  • Thread starter Thread starter Simon Harvey
  • Start date Start date
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
 
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
 
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
 
Back
Top