Wednesday, March 28, 2012

How to format a string when pulling from a Dataitem

I seem to be having a problem in getting a string formatted correctly that I'm pulling from a SQL Datasource.

I'm trying to format a Datalist, and more specifically, a Paypal "Add to Cart" button that's supposed to pass several values to another page. The problem I have is with passing the price amount. All the data is in a SQL Express database and the price field is in the database as "money". However it outputs the dollar amount with too many trailing zeros, for example $6.00 is formatted as 6.0000. I'm trying to pass it into the form variable with this code:

<input type="hidden" name="amount" value="<%# DataBinder.eval(Container.dataitem, "Price", "{0}" %>"
Unfortunately, that tends to make include the trailing zeros and mess up the ability to pass the variable. Can anyone help me with how to format this variable so there's no trailing zeros, just so that $6.00 comes out as 6.00 and not 6.0000?

Thanks

Try this and let me know

<%# FormatCurrency(Container.dataitem("Price"), 2) %>

HTH

Regards

|||That looks like it works beautifully.

Thanks so much.

GZR

No comments:

Post a Comment