Gridview dataformatstring

0 views
Skip to first unread message

William Adams

unread,
Jun 30, 2009, 12:16:28 PM6/30/09
to bs...@googlegroups.com
I am sure many may have encountered this issue in VS 2008, working with .NET 3.5 web apps.

The issue is using "dataformatstring" for a gridview's boundfield. I have a number like 123,000,000, which I want displayed as 123 million. ToString("0,, million") achieves this nicely elsewhere for a label with numbers coming from another datasource. {0:0,, million} fails to work in the boundfield dataformatstring property (same for {0,, million}). For the time being, I have resorted to having the particular datasource query dividing this number by 1 million, and then the dataformatstring property for that column set to {0:0 million}. This to me just seems wrong, but achieves the desired end result.

Would anyone happen to have some insight that might help me understand how I could better achieve this? Everywhere in google is the same thing: set htmlencode = false and/or htmlencodeformatstring = false. This has not resolved it at all for me.

Thanks

Chris Brandsma

unread,
Jun 30, 2009, 12:20:22 PM6/30/09
to bs...@googlegroups.com
For cases like this I tend to use custom formatting.  So instead of passing the value as a number, pass it as a preformatted string.

The thing is you don't have too many formatting rules, so setting it up should be easy.  Then, if you do it correctly, if any other screen needs the same value it can also grab the correctly formatted value, and you don't have to repeat you formatting strings.
--
--------------------------------
Christopher Brandsma
http://www.ChrisBrandsma.com
http://www.ElegantCode.com
Reply all
Reply to author
Forward
0 new messages