我有 Gridview 来显示数据表中的所有数据。
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" Width="100%" PageSize="20"
AutoGenerateColumns="true"
CssClass="applicationList-grid" CellPadding="4" ForeColor="#333333" EmptyDataText="No Data!">
</asp:GridView>
以及绑定(bind)的gridview
string sql = "SELECT * from ApplicationForm";
DataTable dt = GetDataTable(connectionString, sql);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
有一些日期字段。日期在 gridview 中显示为 04/03/2014 00:00:00。我想格式化只有日期没有时间的日期。
我只是尝试 dataformatstring="{MM/dd/yyyy}
但它不起作用。
最佳答案
您可以通过以下用法转换它-
<span><%# Eval("columnname", "{0:MM/dd/yyyy}")</span>'
或者在 SQL 中
CONVERT( VARCHAR(10), "columnname" ,110)
注意 - 110
是国家代码。
关于c# - Gridview 日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24858958/