Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 September 7th, 2004, 02:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Date Formatting in data binding

Hello,

What I need to do is return a date in the format of:

Sept. 7

Where it only returns the month (in short-name format) and day. The closest way I saw was using the "m" format option (returns September 7). I want to be able to do this in a Databinder.Eval expression. A custom method (if possible) could be a possible solution, althought I don't know if you can use methods in the data binding expression.

Or would code-behind binding be preferrable for this?

Thanks,

Brian
__________________
Brian
 
Old September 9th, 2004, 02:27 PM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

The only way I know to achieve this is to declare an Enum in your code-behind and populate it with the abbreviated month names.

Enum Months
  Jan
  Feb
  Mar
  ...
End Enum

This way you juct get the corresponding 4rd month name using the following line...

    Dim month as String = [Enum].GetName(GetType(Months), 3)

since the starting index is 0. I am also still searching for a built-in formatting function but since I can't find one yet, I'm using this approach instead.

Hope this helps!

Regards,
Marlon



Marlon Villarama
 
Old September 9th, 2004, 03:40 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
change your formatstring according to Sept. 7
Hope this helps.

--------------------------------------------
Mehdi.:)
 
Old September 9th, 2004, 04:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The {0:c} is microsoft specific, and I don't think I could implement my own custom formatter. Someone let me know if I'm wrong. At any rate, I implemented something similar to Marlon's idea, except I used a function and a select statement. How I adjusted it was using an ItemDataBound event (I was using a repeater control) and changing the text there.

Thanks for your help,

Brian
 
Old September 9th, 2004, 05:14 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

try this,
<%# DataBinder.Eval(Container.DataItem, "yourdatecolumn","{0:MMM. d}") %>


--------------------------------------------
Mehdi.:)
 
Old September 10th, 2004, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

OK, I'll give it a shot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Formatting MargateFan XSLT 3 August 30th, 2006 07:42 AM
Date formatting jroxit Classic ASP Basics 3 February 26th, 2006 10:07 PM
Date Formatting ozPATT Excel VBA 2 October 31st, 2005 12:03 PM
Formatting the date field in Data Grid abinashpatra ASP.NET 1.0 and 1.1 Basics 2 April 21st, 2005 04:01 AM
Formatting to a Date trekmp ADO.NET 2 March 16th, 2004 01:37 PM





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