GridView中如何实现自定义时间货币等字符串格式?方法一: <asp :GridView ID="GridView1" runat="server"> <columns> <asp :BoundField DataField="CreationDate" DataFormatString="{0:M-dd-yyyy}" HtmlEncode="false" HeaderText="CreationDate" /> </columns> </asp> 将htmlencode设置为false即可 方法二: 使用模板列 <asp :GridView ID="GridView3" runat="server" > <columns> <asp :TemplateField HeaderText="CreationDate" > <edititemtemplate> <asp :Label ID="Label1" runat="server" Text='<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>'> </asp> </edititemtemplate> <itemtemplate> <asp :Label ID="Label1" runat="server" Text=’<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>'> </asp> </itemtemplate> </asp> </columns> </asp> {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 |
|
来自: 悟静 > 《.net和asp.net》