如何在 GridView Eval 中处理来自 sql 的十进制货币格式?

How to handle currency format of decmal from sql inside of GridView Eval?

我的本地机器是土耳其语,如果我 运行 我的 asp.net 应用程序,我可以很容易地从 mysql 数据库中看到我的十进制值,比如 below.it 是我的愿望,一切都是我想要的。我使用了 "Text='<%#Eval("Veri","{0:N}")%>'"。它在我的本地运行良好,但如果我在下面发布结果。我想看到小数点,例如:

DB 我的本地 GridVIEW 我的远程 GridView
234567 234.567,00   234,567.00
1234567 1.234.567,00 1,234,567.00


我的 GridView 代码:

  <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderText="Veri">
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtVeri" runat="server" MaxLength="16" Enabled="false" Text='<%#Eval("Veri","{0:N}")%>' CssClass="form-control input-sm" Style="width: 100%;"></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>

这是我的十进制分贝: 我的结果很棒:(我想要这个)

另一方面:如果我向客户发布我的 asp.net 应用程序:(我不想要这个)

使用下面的代码片段,您可以在 Page_PreInit 上使用 GridView 为页面设置特定的数字格式设置,而无需更改整个 UI 语言。这当然会影响页面上的所有数字格式,而不仅仅是 GridView。

protected void Page_PreInit(object sender, EventArgs e)
    {
        CultureInfo newCultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
        NumberFormatInfo numberFormatInfo = (NumberFormatInfo)newCultureInfo.NumberFormat.Clone();
        numberFormatInfo.NumberDecimalSeparator = ",";
        numberFormatInfo.NumberGroupSeparator = ".";
        numberFormatInfo.NumberDecimalDigits = 2;
        newCultureInfo.NumberFormat = numberFormatInfo;
        System.Threading.Thread.CurrentThread.CurrentCulture = newCultureInfo;
    }

树立文化,你会过得更好。

这可以在 web.config 中使用 <globalization uiCulture="tr" culture="tr-TR" /> 元素在整个站点范围内完成,或者在页面指令 <%@ Page UICulture="tr" Culture="tr-TR" %>

中在页面级别完成