当前位置: 移动技术网 > IT编程>开发语言>.net > 浅析GridView中显示时间日期格式的问题

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

海口招标,黄任老,为国家而战变态版

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

形式

语法

结果

注释

数字

{0:n2}

12.36

 

数字

{0:n0}

13

 

货币

{0:c2}

$12.36

 

货币

{0:c4}

$12.3656

 

货币

"¥{0:n2}"

¥12.36

 

科学计数法

{0:e3}

1.23e+001

 

百分数

{0:p}

12.25%

p and p present the same.

日期

{0:d}

2006年11月25日

 

日期

{0:d}

2006-11-25

 

日期

{0:f}

2006年11月25日 10:30

 

日期

{0:f}

2006年11月25日 10:30:00

 

日期

{0:s}

2006-11-25 10:30:00

 

时间

{0:t}

10:30:00

 

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

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

<asp:boundfield datafield="sj" headertext="时间" readonly="true" dataformatstring="{0:d}" />

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

2. 要绑定的列必须是模板列如下:这样才能看到我们想要看到的效果:2006-11-25

<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中显示时间日期格式的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网