Question

I am currently moving my website from an existing web server to a new machine.

The new machine is WIN Sever 2003 running IIS6. The site is using ASP.Net 2.

I added the following to the <system.web> section in my machine.config file to get the website and any future sites to use South African regional settings instead of the default US settings.

<globalization culture="en-ZA" uiCulture="en-ZA"/>

This has mostly worked - the currency symbols have changed from $ to R as they should, but I have a column in a gridview (a bound field - the DB type is money) which is set as follows:

DataFormatString="{0:c}"

[Edit] - have tried this with {0:C} as well as per Richard's suggestion below: still no luck

This is still returning 10000.0000 instead of R 10,000.00 as it was on my old server.

Any ideas as to how to fix this?

Thanks!

[Edit] - I'm beginning to think that this has little to do with the actual culture settings.

I have another form where it works fine:

<ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Balance", "{0:c}") %>'></asp:Label>
</ItemTemplate>

The form that doesn't work uses the gridview without a template:

<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" DataFormatString="{0:C}" >
    <ItemStyle CssClass="al-r" />
</asp:BoundField>
Was it helpful?

Solution 3

thanks for your help with this.

I solved this problem by installing Service pack 2 of ASP.Net 2.0 - after the reboot, the grid worked fine with {0:C}.

This problem would have fixed itself in the production environment as it will be set to update automatically. Currently we have the new server on the local office network and our firewall seems to be restricting the updates.

Lesson learned: always make sure that all your server software is up to date!

OTHER TIPS

On your bound field try setting HtmlEncode="false".

<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" DataFormatString="{0:C}" HtmlEncode="false">
    <ItemStyle CssClass="al-r" />
</asp:BoundField>

MSDN shows a capital C for currency, not lower case.

(Formatting specifiers are case sensitive.)


Update: Now test things here.

Code:

class Program {
    static void Main(string[] args) {
        decimal val = 1234567.89M;

        using (var file = new FileStream(args[0], FileMode.Create, FileAccess.Write))
        using (var output = new StreamWriter(file, Encoding.UTF8)) {
            output.WriteLine("Thread culture: " + Thread.CurrentThread.CurrentCulture.Name);
            output.WriteLine("Thread UI culture: " + Thread.CurrentThread.CurrentUICulture.Name);

            var cultures = new[] { "en-US", "en-GB", "af-ZA", "fr-FR", "fr-CA" };
            foreach (var culture in cultures) {
                var ci = new CultureInfo(culture);
                output.WriteLine(String.Format(ci, "{0,-10}: {1:C}", ci.Name, val));
            }
        }
    }
}

Gives output:

Thread culture: en-GB
Thread UI culture: en-US
en-US     : $1,234,567.89
en-GB     : £1,234,567.89
af-ZA     : R 1,234,567.89
fr-FR     : 1 234 567,89 €
fr-CA     : 1 234 567,89 $

Which looks OK to me.

How are you setting the culture?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top