David Adlington
David Adlington

Reputation: 666

Setting Property for Percentage Format ASP.Net

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

Upvotes: 1

Views: 6317

Answers (3)

bbmud
bbmud

Reputation: 2688

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

Upvotes: 0

to StackOverflow
to StackOverflow

Reputation: 124696

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.

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 190905

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.

Upvotes: 0

Related Questions