2

如何在datagridview中格式化空日期时间?我以编程方式创建 datagridview 列,在表单加载

DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Format = "dd-MM-yyyy";

DataGridViewTextBoxColumn updatedDateColumn = new DataGridViewTextBoxColumn();
updatedDateColumn.DataPropertyName = "UpdatedDate";
updatedDateColumn.HeaderText = "Updated Date";
updatedDateColumn.Name = "UpdatedDate";
updatedDateColumn.DefaultCellStyle = style;

问题是当更新日期值为空时 datagridview 显示 01/01/0001 12:00:00

我试图编辑

style.NullValue = string.Empty;

但它没有工作如何解决这个问题?谢谢

4

1 回答 1

0

您可以使用 ISNULL 在 sql server 中将 null 日期设置为 null 并将 datagridviewCellStyle 的 NullValue 属性设置为 string.Empty ;像这个在 sql server

ISNULL(DateColumnName , NULL) and set style.NullValue = string.Empty   

在 dataGridViewCellStyle

于 2014-04-03T00:31:35.853 回答