Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2009, 10:40 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default Formatting date and time

Hi,
I am using the following in gridviews:
Code:
<Columns>
                                    
<asp:BoundField DataField="EventDate"
HeaderText="Date" 
ItemStyle-Width="120"  
SortExpression="EventDate" 
DataFormatString="{0:d MMMM yy}"
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
                    
<asp:BoundField DataField="Time" HeaderText="Time"   
ItemStyle-Width="75"
 SortExpression="Time"
DataFormatString="{0:h:mm tt}" >
 <ItemStyle HorizontalAlign="center" />
 </asp:BoundField>
........... other columns
</columns>
The [EventDate] field formats correctly as for example 12 July 09
BUT..the [Time] field seems to ignore the DataFormatString appearing as 15:09:34

EventDate is datatype Date
Time is datatype Time

So what am I missing?
__________________
Geoff Baldwin
 
Old July 28th, 2009, 10:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this related to the book Beginning ASP.NET in C# and VB.NET? If so, can you specify a page number or chapter?

If it isn't related, can you post generic ASP.NET questions like this one in one of the generic ASP.NET categories: http://p2p.wrox.com/asp-net-3-5-436/ Makes it easier for me and others to manage relevant threads.

That said, try setting the HtmlEncode property of the BoundField to False....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 28th, 2009, 06:06 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Hi Imar
I was using information from Chapter 12 p408 to guide me in displaying a date correctly.

I opted to use custom formats as that is what I found on various web sites.

As I say, the date works just fine, but the time seems to refuse to format.
Setting the HtmlEncode and/or the HtmlEncodeFormatstring propertyto False makes no difference.

So I guess there is something wrong with my Time Datatype in the database. I've changed it to DateTime and all works so I'll be happy with that!
(Don't like being beaten tho )
__________________
Geoff Baldwin





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Time Output braunj ASP.NET 2.0 Basics 0 October 6th, 2008 10:27 PM
Formatting and creating date and Time Audioicon ASP.NET 3.5 Basics 3 September 22nd, 2008 07:58 PM
formatting date time Adam H-W Classic ASP Basics 4 September 29th, 2004 03:35 AM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.