【问题标题】:ASP listview format price string with ',' seperatorASP listview 格式打印字符串,带“,”分隔符
【发布时间】:2015-05-07 08:38:34
【问题描述】:

我有 listview 的 asp.net 网站。其中一列是产品价格。我想在价格中添加分隔符 ','

如果数据库中的价格是 1250,我希望 listview 显示 1,250。价格字段为string 类型。

我尝试了以下但我得到 1250 没有分隔符:

<asp:Label ID="Label5" runat="server" Text='<%# Eval("price","{0:n0}")%>'/>

 <asp:Label ID="Label5" runat="server" Text='<%# String.Format("{0:n0}", Eval("price"))%>'/>

【问题讨论】:

  • 请试试这个:lblTotal.Text = String.Format("{0:#,###,###.##}", (object)total); 这里total 包含值。在你的情况下 1250
  • 可能是因为价格是字符串而不是数字类型。如果它是像 decimalint 这样的数字类型,它可以工作:string.Format("{0:N0}",1250)
  • 我不想从后面的代码中做到这一点,但如果可能的话,从 listview 项目开始。
  • 试试这个:Text='&lt;%# Eval("price","{0:#,###,###.##}") %&gt;
  • 正确的。有什么办法可以用字符串做到这一点?

标签: asp.net string string-formatting


【解决方案1】:

试试这个

 <asp:Label ID="Label5" runat="server" Text='<%# String.Format("{0:N2}", Convert.ToInt64(Eval("price")))%>'/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    相关资源
    最近更新 更多