c# - 不要在 gridview 中显示日期时间最小值

标签 c#

给出:

public class Customer
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public DateTime Birthdate { get; set; }
}

我有一些未输入生日的列表,因此当我绑定(bind)到 GridView 时,它显示 DateTime.MinValue。如果生日是 DateTime.MinValue,有哪些不同的方法可以在 gridview 中显示空白?

最佳答案

除非它被映射到一个数据库,否则我会让它可以为空:

public class Customer
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public DateTime? Birthdate { get; set; }
}

编辑:

如果它是映射的,那么我会为它创建一个只读的可空值:

public DateTime? BirthdateDisplay
{
   get
   {
      if (this.Birthdate == default(DateTime))
         return null;
      else
         return this.Birthdate;
   }   
}

关于c# - 不要在 gridview 中显示日期时间最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10357000/

相关文章:

c# - Xamarin 形成 Xaml 转换器 : Bindable property

c# - 使用反射映射相似对象 : Object does not match target type

c# - IIS应用程序池回收和 native 程序集

c# - System.ArgumentNullException:值不能为null。 (参数 'connectionString')asp.net Core Docker-compose

c# - 使用空格时,Azure 搜索的 search.in 不返回结果

c# - 相同的 XAML,但用户控件背后的代码不同

c# - 在 .Net 核心 2 中使用 SQL Server 文件流

c# - ListView.RetrieveVirtualItem 事件到底是什么 - C#

c# - 指定 ArrayList 元素的类型

c# - 使用 WPF 应用程序目录打开 Windows 资源管理器