Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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
  #1 (permalink)  
Old November 17th, 2003, 04:35 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting datagrid column dates

I have a bound datagrid ( bound to a dataview ). One of the
fields is a datetime field. I wish to format the date display
of this bound datetime column. Instead of showing
dd/mm/yyy hh:mm:ss - I wish to show just dd/mm/yyyy.

Do I use a column style to format the date?
If so how? Can anyone point me to examples
of formatting bound datagrid columns ?

Thanks.
  #2 (permalink)  
Old November 17th, 2003, 04:47 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Here is the list of BoundColumn members:
http://msdn.microsoft.com/library/de...mberstopic.asp

One of them is DataFormatString:
http://msdn.microsoft.com/library/de...tringtopic.asp

Here's the overview for formatting:
http://msdn.microsoft.com/library/de...ngOverview.asp

And here are details for date and time string formats:
http://msdn.microsoft.com/library/de...matstrings.asp

Peter
------------------------------------------------------
Work smarter, not harder.
  #3 (permalink)  
Old November 18th, 2003, 05:07 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry dont quite understand.
Is the dataformatstring under datagrid.columns.?
I cant find any examples at MS.
How do I set the formatstring on my grid column?
  #4 (permalink)  
Old November 18th, 2003, 01:18 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

<asp:BoundColumn ... DataFormatString="dd:MM:yyyy"></asp:boundcolumn>

Peter
------------------------------------------------------
Work smarter, not harder.
  #5 (permalink)  
Old November 19th, 2003, 08:13 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Thanks Peter
I didn't realise I could edit the HTML directly
and place formatting code in there (still learnin').


  #6 (permalink)  
Old August 7th, 2004, 04:35 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi-
I needed the same thing and tried the format, but it displays "dd:mm:yyyy" instead of the real value. What I am doing wrong here? Your response will be greatly appreciated.
Thanks
Renu


Quote:
quote:Originally posted by planoie
 <asp:BoundColumn ... DataFormatString="dd:MM:yyyy"></asp:boundcolumn>

Peter
------------------------------------------------------
Work smarter, not harder.
  #7 (permalink)  
Old August 9th, 2004, 12:35 PM
Authorized User
 
Join Date: May 2004
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

change the date into a string before you put it into dataview :D

  #8 (permalink)  
Old January 5th, 2005, 03:10 AM
Registered User
 
Join Date: Jan 2005
Location: ak, na, New Zealand.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to iecanfly
Default

Try DataFormatString="{0:dd-mm-yyyy}"
hope this helps

Quote:
quote:Originally posted by Renu
 Hi-
I needed the same thing and tried the format, but it displays "dd:mm:yyyy" instead of the real value. What I am doing wrong here? Your response will be greatly appreciated.
Thanks
Renu


Quote:
quote:Originally posted by planoie
 <asp:BoundColumn ... DataFormatString="dd:MM:yyyy"></asp:boundcolumn>

Peter
------------------------------------------------------
Work smarter, not harder.


love never fails
  #9 (permalink)  
Old January 5th, 2005, 05:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

<asp:BoundColumn DataField=startDate HeaderText="startDate" DataFormatString="{0:dd-MMM-yyyy HH:mm:ss}">
</asp:BoundColumn>

Hope this code snippet helps!


Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
  #10 (permalink)  
Old February 4th, 2005, 11:37 AM
Registered User
 
Join Date: Feb 2005
Location: Manhattan, New York, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ulver
Default

For short date use the following DataFormatString:

{0:d}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Dates dhoward SQL Language 4 January 30th, 2007 04:00 PM
Column Sorting/Formatting in MS Datagrid! ao7711 C# 1 July 13th, 2006 02:32 PM
Formatting For Between Dates hcweb Classic ASP Basics 7 February 8th, 2005 02:29 AM
Data Formatting in DataGrid Template Column djmarquette ADO.NET 3 April 14th, 2004 07:25 AM
Formatting Dates Louisa VB.NET 2002/2003 Basics 3 March 16th, 2004 05:52 AM





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