页面中有一个Gridview控件,其前台代码有以下一句,如:
<asp:BoundField DataField="Vehicle_BuyDate" HeaderText="购置日期" DataFormatString="{0: yyyy-MM-dd}"/>就是想使显示的日期数据为:2009-07-29 这样的格式,可是实际显示的还是诸如:2009-07-29 13:27:03 这种样子,没法去掉时分秒部分。害得我还得在后台的GridView1_RowDataBound(object sender, GridViewRowEventArgs e)事件中加入以下代码,如:
string date = Convert.ToDateTime(e.Row.Cells[9].Text).ToShortDateString(); //购置日期
e.Row.Cells[9].Text = date;
才能显示为:2009-07-29。请问这是怎么回事?
<asp:BoundField DataField="Vehicle_BuyDate" HeaderText="购置日期" DataFormatString="{0: yyyy-MM-dd}"/>就是想使显示的日期数据为:2009-07-29 这样的格式,可是实际显示的还是诸如:2009-07-29 13:27:03 这种样子,没法去掉时分秒部分。害得我还得在后台的GridView1_RowDataBound(object sender, GridViewRowEventArgs e)事件中加入以下代码,如:
string date = Convert.ToDateTime(e.Row.Cells[9].Text).ToShortDateString(); //购置日期
e.Row.Cells[9].Text = date;
才能显示为:2009-07-29。请问这是怎么回事?
<ItemStyle Width="10%" CssClass="bottomLine" Wrap="False" HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("fldcreatedate","{0:[yyyy-MM-dd]}").ToString() %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
你也可以在后台处理.ToString(yy-MM-dd);Datetime类型可以格式,然后界面Eval()绑定处理格式的那个方法