views:

87

answers:

2

Is there a built in FormatString or a way to use a custom FormatString to take:
$150.00
$1,170.00
$12,170.00
$90.00
$38.00
$750.00

And format them like:

$    150.00
$  1,170.00
$ 12,170.00
$     90.00
$     38.00
$    750.00

without knowing the largest value? This is in a gridview boundcolumn I am currently in the codebehind on rowdatabound looping through the existing rows to get the largest and changing the current one if necessary or changing the existing ones if the current one is the largest, so I have a workaround but was hoping for a clean solution.

+1  A: 

To the best of my knowledge, there is no way to pad a string with spaces without knowing the maximum length and to get the maximum length you would need to know the maximum value.

Have you considered the use of an alignment property on the column? You would get the following, which is not quite exactly what you are looking for.

   $150.00
 $1,170.00
$12,170.00
    $90.00
    $38.00
   $750.00
Patrick McDonald
+2  A: 

If you have the numbers, and the currency will be the same, why not just use a template column in your grid, have a span floated left with the currency and a span floated right with the amount. Could save a lot of hassle...

Paddy
+1, Sounds like the ideal solution to me
Patrick McDonald