Solved

Formatting Fields in custom binding in asp.net 2.0

Posted on 2006-11-13
5
368 Views
Last Modified: 2008-02-01
Hello...

I am using Visual Web Developer 2005 and I created a sql datasource and bound it to a formview.  In my ItemTemplate I need to show a number field as currency or 125422.55 as $125,422.55.  When I go to Edit Databinding for that field it has Custom Binding selected and Bind("fieldname") in the textbox.  Doesn't seem like there is anywhere obvious to format the field.  

Thanks!
0
Comment
Question by:kenadelglass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 17931160
have you tried using DataFormatString?

so in your custom binding, have this in your tag line

dataformatstring="${0:C2}"




0
 
LVL 9

Expert Comment

by:kraffay
ID: 17931244
Can you set a HTMLEncode = "false" in your template?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 100 total points
ID: 17931286
You actually need to do both.

1) Set HTMLEncode = False
2) Set the DataFormatString to {0:c}

You don't need the $ symbol at the start because that is added for you depending on the current Culture.
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17931553
You can have total control over the foprmat if you use...

myNumber.ToString("$" & "#,###.00")

This will use 2 decimal places, comma seperators and the currency symbol of your choice irrespective of the locale. If I were to browes a US site fomr the UK and you were using the locale to set the currency symbol, I would not be seeing the correct price (exchange rates).

Of course you can ignore this if you do want to use the servers locale to set the client side formatting.



0
 
LVL 1

Author Comment

by:kenadelglass
ID: 17932335
I sort of figured it out myself but the answers led to the right place...This was the binding statement that worked...

Bind("Networth", "{0:C}")

Thanks all for your efforts!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question