给出:
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/