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

原文地址:https://www.cnblogs.com/songsh96/p/921746.html