方法一:
<ItemTemplate>
<%# Eval("InspectionDate", "{0:yyyy-MM-dd}")%>
</ItemTemplate>
</asp:TemplateField>
方法二:
<ItemTemplate>
<%# string.Format("{0:yyyy-MM-dd}", Eval("InspectionDate")%>
</ItemTemplate>
</asp:TemplateField>
方法三:
先在TemplateField中放一个Label控件
<ItemTemplate>
<asp:Label ID="LabelInspectionDate" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
然后在cs中写OnRowDataBound事件
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.FindControl("LabelInspectionDate") != null)
{
Label labelInspectionDate = (Label)e.Row.FindControl("LabelInspectionDate");
labelInspectionDate.Text = string.Format("{0:yyyy-MM-dd}",drv["InspectionDate"]);
}
}
}
方法五:
此方法和方法四有点相似,只是引用InsusDateTimeUtility自定义类别
{
InsusDateTimeUtility objInsusDateTimeUtility = new InsusDateTimeUtility();
DataRowView drv = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.FindControl("LabelInspectionDate") != null)
{
Label labelInspectionDate = (Label)e.Row.FindControl("LabelInspectionDate");
labelInspectionDate.Text = objInsusDateTimeUtility.GetDateTime(drv["InspectionDate"], "yyyy-MM-dd");
}
}
}