用逗号分隔数以千计的 asp.net [英] Separate number with comma for thousands asp.net

查看:20
本文介绍了用逗号分隔数以千计的 asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在asp.net gridview上用逗号分隔每千个数字(后面有c#)

How do you do separate numbers with commas for every thousand on asp.net gridview (with c# in the back)

我一直在后端(单独)尝试以下几行(没有任何效果,它们只是截断了小数位)

I have been trying the following lines (individually) in the backend(nothing works, they just cut off the decimal places)

row["Applied_Amount_Varience_Sum"] = string.Format("{0:#,###0}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("#,##0.00"); 
row["Applied_Amount_Varience_Sum"] = String.Format("{0:n}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("N0");

row 是对数据库中表的引用(我正在遍历返回的每个对象并遍历行)

row is a reference to the table in the database (I am looping through each object returned and going through the rows)

我把它放在我绑定到 gridview 的地方.所以基本上我就在它绑定之前我将这些属性更改为有一个逗号,但它没有这样做

I have putting this where I bind to the gridview. So basically I right before it binds I change those attributes to have a comma but it doesn't do that

我试过的台词会改变这一点

The lines I tried will change this

1092.00

到这里

1092

但我正在努力实现这一目标

but I am trying to achieve this

1,092

* 编辑 *

这是在模板字段中(因为我需要它是一个带有 onclick 功能的链接

This is within a template field (because I needed it to be a link with an onclick function

<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Applied Amount Variance">
  <ItemTemplate>
    <asp:LinkButton ID="LbPath" runat="server" 
                    Text='<%# Eval("Applied_Amount_Varience_Sum") %>'
                    CommandName="BindExpand" 
                    OnCommand="BindExpand"
                    CommandArgument='<%#Bind("Applied_Amount_Varience_Sum") %>'>
    </asp:LinkButton>
  </ItemTemplate>
</asp:TemplateField>

推荐答案

如果您正在寻找货币使用

IF you are looking for Currency use

DataFormatString="{0:c}"

否则使用

DataFormatString="{0:N2}"

试试

    Text='<%# Eval("Applied_Amount_Varience_Sum","{0:c}") %>'

    Text='<%# Eval("Applied_Amount_Varience_Sum","{0:N2}") %>'

这篇关于用逗号分隔数以千计的 asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆