GridView中的数字格式化

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"/>

posted on 2007-10-12 08:14  Sammy  阅读(941)  评论(0编辑  收藏  举报

导航