Solved

Formatting Fields in custom binding in asp.net 2.0

Posted on 2006-11-13
5
364 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SignalR's 'connection.Hub' only returns the Hub on the first page 1 26
Problem to refer to value 8 49
Regex validation 2 24
tutorial for ebay api 3 34
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 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