views:

639

answers:

3

Applogies for what I have no doubt is a noob question.

I display several percentage values in a Grid View in ASP.Net

I want to be able to set the NumberFormatInfo.PercentPositivePattern Property which I think I have to bring in a Globals "property" to be able to adjust?

from its Default 0 to 1

This is the property I need to adjust

http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.percentpositivepattern(VS.71).aspx

I just cannot figure out how to do it! :(

This will remove the space between the % and the numbers.

How can I do this for the entire application?

Can I put some code in the WebConfig or?

Thanks

A: 

I am unsure if you can set it in a web.config file, but what you can do, is inherit from the grid view, set the property in the constructor and use that new subclass.

Daniel A. White
Sorry!How exactly would I do that?
David A
+1  A: 

You can change System.Globalization.CultureInfo.CurrentCulture to whatever you want at the start of each request (e.g. in Application_BeginRequest in global.asax).

Of course this will affect all values displayed by your application, not just those displayed in a GridView.

Joe
A: 

You can modify the format using the DataFormatString property on the BoundField:

<asp:BoundField DataField="YourPropertyName" DataFormatString="#0.##%" />

You can set the format to the custom format you like, according to this article:

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

bbmud