区域设置 IIS6 和 ASP.Net 2 - {0:c} 在 gridview 中返回太多小数
我目前正在将我的网站从现有的网络服务器迁移到新机器。
新机器是WIN Sever 2003,运行IIS6。 该网站使用 ASP.Net 2。
我将以下内容添加到 machine.config 文件中的
部分,以使网站和任何未来的网站改用南非区域设置美国默认设置。
<globalization culture="en-ZA" uiCulture="en-ZA"/>
这基本上有效 - 货币符号已从 $ 更改为 R,因为它们应该,但我在 gridview 中有一个列(绑定字段 - 数据库类型是货币),设置如下:
DataFormatString =“{0:c” }"
[编辑] - 已使用 {0:C} 以及下面 Richard 的建议进行了尝试:仍然没有运气
这仍然返回 10000.0000,而不是 R 10,000.00,因为它在我的旧服务器上。
关于如何解决这个问题有什么想法吗?
谢谢!
[编辑] - 我开始认为这与实际的文化设置关系不大。
我有另一种工作正常的表单:
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Balance", "{0:c}") %>'></asp:Label>
</ItemTemplate>
不起作用的表单使用没有模板的 gridview:
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" DataFormatString="{0:C}" >
<ItemStyle CssClass="al-r" />
</asp:BoundField>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的绑定字段上尝试设置 HtmlEncode="false"。
On your bound field try setting HtmlEncode="false".
MSDN 显示货币为大写 C,而不是小写。
(格式说明符区分大小写。)
更新:现在在此处进行测试。
代码:
给出输出:
对我来说看起来不错。
你如何设定文化?
MSDN shows a capital C for currency, not lower case.
(Formatting specifiers are case sensitive.)
Update: Now test things here.
Code:
Gives output:
Which looks OK to me.
How are you setting the culture?
感谢您对此的帮助。
我通过安装 ASP.Net 2.0 的 Service pack 2 解决了这个问题 - 重新启动后,网格在 {0:C} 下工作正常。
这个问题在生产环境中会自行修复,因为它将被设置为自动更新。 目前,我们在本地办公网络上拥有新服务器,而我们的防火墙似乎限制了更新。
经验教训:始终确保所有服务器软件都是最新的!
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!