GridView绑定时间显示的各种格式

绑定格式:

<asp:BoundField DataField="PlanStartDate" HeaderText="开始日期" 
                            DataFormatString="{0:yyyy-MM-dd}" />

模板列:

 <asp:TemplateField HeaderText="开始日期">
                            <ItemTemplate>
                                <asp:Label Text='<%#Eval("PlanStartDate","{0:yyyy-MM-dd}") %>' DataFormatString="{0:yyyy-MM-dd}" ID="labPlanStartDate" runat="erver"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>

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-26 10:30:00  
时间 {0:T} 10:30:00  


在设置gridview等数据绑定控件的模版列时,总要设置显示的格式,这里是我查询一些资料后统计出来的。
还有一个常规的选项是用数据库中默认的格式显示。

以下是一个例子
 <asp:Label ID="Label2" runat="server" Text='<%# Eval("dtt","{0:d}") %>'></asp:Label> 

posted on 2013-05-17 14:26  小东北  阅读(3937)  评论(0编辑  收藏  举报