All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
GridView绑定模板格式化日期总结_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:02:12 Browse times: 331 Comment times: 0

GridView绑定模板格式化日期总结_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

GridView绑定模板格式化日期总结_[Asp.Net教程]

问题描述:GridView模板列绑定数据库中的T_LogDate字段,然后读取系统时间。代码如下:

<%# Eval("T_LogDate").ToString() %>显示结果是:2008-01-26 14:03:59;我现在要就显示2008-01-26。
很简单,看下面代码:
<%# Eval("T_LogDate", "{0:yyyy-MM-dd}").ToString()%>大功告成!
注意:此功能只针对模板列控件。

关于格式化问题,还有一种思路就是从数据库中读取相关字段,在SQL语句中格式化输出。
代码如示:select convert(varchar(10),字段名) as 时间 from 表名比如上面例子就应该这样写:select convert(varchar(1000),T_LogDate,105) as 时间 from T_Information注意:当数据量比较大的时候,效率是个问题。一般不推荐!总结一下格式:形式语法结果注释数字{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-26 10:30:00 时间{0:T}10:30:00 在设置GridView数据绑定控件的模版列时,总要设置显示的格式,这里是我查询一些资料后统计出来的。还有一个常规的选项是用数据库中默认的格式显示。
来源:http://blog.csdn.net/codeshark




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.