在 aspx 页面中,我绑定如下标签:
<asp:TemplateField HeaderText="Date of Joining">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("date_of_joining") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid Priviledge Date">
<ItemTemplate>
<asp:Label ID="Label8" runat="server"
Text='<%# Eval("paid_priviledge_date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
在后面的代码中,我像这样绑定网格视图:(给出了最小代码)
GridView1.DataSource = dt2;
GridView1.DataBind();
但 gridview 列显示日期如下:
4/12/2011 12:00:00 AM
4/4/2011 12:00:00 AM
请建议如何删除时间戳部分并仅显示日期部分。
我知道如何通过使用 ToString 和 SubString 进行格式化来做到这一点。但我无法在 gridview 中执行此操作。
您可以为 eval 语句指定格式字符串:
Eval("date_of_joining", "{0:dd/MM/yyyy}")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)