Solved

Formatting Fields in custom binding in asp.net 2.0

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now