Solved

Formatting Fields in custom binding in asp.net 2.0

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

860 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