GridView中如何实现自定义时间货币等字符串格式?

 1 方法一:
 2 <asp :GridView ID="GridView1" runat="server">
 3 <columns>
 4 <asp :BoundField DataField="CreationDate" 
 5 DataFormatString="{0:M-dd-yyyy}" 
 6 HtmlEncode="false"
 7 HeaderText="CreationDate" />
 8 </columns>
 9 </asp>
10 将htmlencode设置为false即可
11 方法二:
12 使用模板列
13 <asp :GridView ID="GridView3" runat="server" >
14 <columns>
15 <asp :TemplateField HeaderText="CreationDate" >
16 <edititemtemplate>
17 <asp :Label ID="Label1" runat="server" 
18 Text='<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>'>
19 </asp>
20 </edititemtemplate>
21 <itemtemplate>
22 <asp :Label ID="Label1" runat="server" 
23 Text=’<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>'>
24 </asp>
25 </itemtemplate>
26 </asp>
27 </columns>
28 </asp>

附录-常用格式化公式:
{0:C}  货币;

{0:D4}由0填充的4个字符宽的字段中显示整数;
{0:000.0}四舍五入小数点保留第几位有效数字;
{0:N2}小数点保留2位有效数字;{0:N2}%   小数点保留2位有效数字加百分号;
{0:D}长日期;{0:d}短日期;{0:yy-MM-dd}   例如07-3-25;;{0:yyyy-MM-dd}  例如2007-3-25

原文地址:https://www.cnblogs.com/xyyt/p/3205357.html