★搜Asp.net★(
www.soAsp.net
),为专业技术文档网站。
包括Asp.net开发技术文档·C#开发技术文档·Access/SQL Server数据库开发技术文档·VB.NET开发技术文档。
还包括·项目实战经验总结·开发经验技巧总结·项目开发心得。
GridView显示时间列时,设置时间的格式
GridView的某一列需要绑定一个时间字段,如果直接绑定,时间的格式会是2000-1-1 9:12:12这样的。如果我们想个性化一些,比如2000年1月1日 9:12这样,怎么实现呢?这就需要用到模板列,以下两种方式均可实现
1、
1
<
asp:TemplateField
HeaderText
="注册时间"
>
2
<
ItemTemplate
>
3
<
asp:Literal
ID
="literalName"
runat
="server"
Text
='<%#
Eval("AddTime","{0:yyyy年MM月dd日 HH:mm}") %
>
'>
</
asp:Literal
>
4
</
ItemTemplate
>
5
</
asp:TemplateField
>
2、
1
<
asp:TemplateField
HeaderText
="注册时间"
>
2
<
ItemTemplate
>
3
<
asp:Literal
ID
="literalName"
runat
="server"
Text
='<%#
Convert.ToDateTime(Eval("AddTime")).ToString("yyyy年MM月dd日 HH:mm") %
>
'>
</
asp:Literal
>
4
</
ItemTemplate
>
5
</
asp:TemplateField
>