GridView中数字列格式汇总

利用BoundField.DataFormatString 属性,实现起来比较简单,不过要注意的是,必须和HtmlEncode="False"联合起来用,否则DataFormatString 不起作用

例1:
<asp:BoundField DataField="Total" HeaderText="Total"  DataFormatString="{0:n2}" HtmlEncode="False" />

例2: 使用模版

<asp:textbox id="TextBoxPrice"    text='<%# Bind("Price", "{0:c}") %>'         runat="server"/>

 

string   aa   =   money.ToString("#,##0");  
  
  
  string   s=i.ToString("###,###.00");  
  
  
  String.Format("{0:N}",   i   )  
  
  
  string.Format("{0:#,#}",Convert.ToInt32(GetBoundData("Price")));  
  
  
  GetBoundData("Price").ToString("N2");

 

 

形式语法结果注释
数字{0:N2}12.36
数字{0:N0}13
货币{0:c2}$12.36
货币{0:c4}$12.3656
货币"¥{0:N2}"¥12.36
科学计数法{0:E3}1.23E+001
百分数{0:P}12.25%P and p present the same.
日期{0:D}2006年11月25日
日期{0:d}2006-11-25
日期{0:f}2006年11月25日 10:30
日期{0:F}2006年11月25日 10:30:00
日期{0:s}2006-11-26 10:30:00
时间{0:T}10:30:00
在设置 GridView数据绑定控件的模版列时,总要设置显示的格式,
这里是我查询一些资料后统计出来的。还有一个常规的选项是用数据库中默认的格式显示。

转载于:https://www.cnblogs.com/huige1004/archive/2009/03/25/1421499.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值