【发布时间】: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 -
可能是因为价格是字符串而不是数字类型。如果它是像
decimal或int这样的数字类型,它可以工作:string.Format("{0:N0}",1250) -
我不想从后面的代码中做到这一点,但如果可能的话,从 listview 项目开始。
-
试试这个:
Text='<%# Eval("price","{0:#,###,###.##}") %> -
正确的。有什么办法可以用字符串做到这一点?
标签: asp.net string string-formatting