好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

浅析GridView中显示时间日期格式的问题

以下都是GridView基本常用的日期,时间格式

形式

语法

结果

注释

数字

{0:N2}

 

数字

{0:N0}

 

货币

{0:c2}

 

货币

{0:c4}

 

货币

"¥{0:N2}"

 

科学计数法

{0:E3}

 

百分数

{0:P}

12.25%

P and p present the same.

日期

{0:D}

2006年11月25日

 

日期

{0:d}

 

日期

{0:f}

 

日期

{0:F}

 

日期

{0:s}

 

时间

{0:T}

 

在GridView中操作的时候要注意以下的几个方面(以{0:d}为例)

1. 要绑定的列如果单纯的是boundfiled类型的(如下)

<asp:BoundField DataField="sj" HeaderText="时间" ReadOnly="True" DataFormatString="{0:d}" />

显示出来的格式还是2006-11-25 0:00:00 为达到我们想要的效果

<asp:TemplateField HeaderText="时间">

  <EditItemTemplate>

     <asp:Label ID="Label1" runat="server" Text='<%# Eval("sj", "{0:d}") %>'></asp:Label>

</EditItemTemplate>

<ItemTemplate>

     <asp:Label ID="Label2" runat="server" Text='<%# Bind("sj", "{0:d}") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

以上这篇浅析GridView中显示时间日期格式的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

查看更多关于浅析GridView中显示时间日期格式的问题的详细内容...

  阅读:39次