【问题标题】:Fix date format to not show time on BoundColumn修复日期格式以在 BoundColumn 上不显示时间
【发布时间】:2017-12-23 04:58:53
【问题描述】:

我正在尝试将日期格式更改为仅在 DataGrid 上的 BoundColumn 中显示日期而不是时间,但到目前为止我没有尝试过任何工作。

<asp:BoundColumn DataField="InvoiceDate" HeaderText="Date" DataFormatString = "{0:MM-dd-yyyy}"/>

我也试过了:

DataFormatString="{0:dd-M-yyyy}"
DataFormatString="{0:d}"
DataFormatString="{0:MMM-d-yyy}"

【问题讨论】:

  • 您可以在后面的代码中执行此操作。
  • 使用 DataGrid 控件对其进行了测试。有效,不显示时间。

标签: c# asp.net datagrid date-formatting boundcolumn


【解决方案1】:

这是我在表格中使用的格式字符串,它只显示日期:

<asp:BoundField HeaderText="Date" DataField="Date"
     SortExpression="Date" DataFormatString="{0:dd/MM/yyyy}" />

一个有趣的警告是,这会将日期呈现为使用dd-MM-yyyy 格式化,但区域设置可能会在其中发挥作用。

【讨论】:

  • 没有没有用,它仍然在网格上显示时间。
  • 请更新您的问题并向我们展示您正在使用的日期时间值的示例。我有一种感觉,它们实际上不是日期时间值,而是字符串值
  • 该字段是数据库中的日期时间,在网格上显示为 03/06/2017 00:00:00
  • 只是想知道在该控件中添加 HtmlEncode="false" 是否有帮助?由于我不知道其他想法,可能会尝试 DataFormatString="{0:d}" - 这是日期的简写版本,但您的应该也可以。
猜你喜欢
  • 2017-04-03
  • 2019-05-20
  • 1970-01-01
  • 1970-01-01
  • 2011-05-12
  • 1970-01-01
  • 1970-01-01
  • 2020-04-14
  • 2014-04-15
相关资源
最近更新 更多