最近老在做GridView方面的内容,于是顺手把GridView中绑定相关的一些经验总结一下。先开一贴,以后随时补充。
1、GridView绑定日期格式化:
a、写在绑定列中:
<asp:BoundField DataField="Time" HeaderText="时间" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode=false ReadOnly="True" />
这里要注意的是,必须要加上“HtmlEncode=false”,否则不能正常显示。
b、写在模板列中:
<ItemTemplate>
<asp:Label ID="lblTime" runat="server" Text='<%# Bind("Time", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>