I'd suggest one of the following:

1) Extend your object so you can have a property that formats your
number appropriately, and use that property instead of the normal
one.  For example, assuming the original property name is Cost, build
a CostExtended string property that formats your number the way you
want, then bind CostExtended to the grid.

2) Use a templatefield instead of a boundfield in your grid.  Then,
use inline code to format your value appropriately, like the following
- it's a little messy, but if you can't modify the data source, this
might work for you (no promises on the exact syntax - I didn't double-
check it):
<%# ((MyObjectType)Container.DataItem).Cost == 0 ? "-" :
((MyObjectType)Container.DataItem).Cost.ToString("##.### ;(##.###)")
%>

The trailing space might be a bit tricky - in a web page, aligning
space like that isn't the easiest thing in the world, so you may have
to give that some extra thought...But at least this will get your .NET
string formatted correctly.

On Mar 31, 10:52 am, Ran_dst <[email protected]> wrote:
> Hi,
>
> In a GridView how can I format a number as follows?
> Show a dash (-) if the value is 0
> Show negative numbers in brackets
> Show a trailing space if the value is positive
> ?
>
> Thanks in advance!

Reply via email to