在dataGridView中,数据库为MS SQL2000的时候,它的日期显示为:2007-12-16 10:57而我希望显示的是:2007-12-16可以通过dataGridView的CellFormatting事件添加:private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEvent
在dataget='_blank'>GridView中,数据库为MS SQL2000的时候,它的日期显示为:
2007-12-16 10:57
而我希望显示的是:
2007-12-16
可以通过dataGridView的CellFormatting事件添加:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 3)//假设第3列为显示日期的列
{
e.Value = Convert.ToDateTime(e.Value).ToShortDateString();
}
}
除了这种方法之外,我们也可以在查询语句中就格式化好日期,比如下面这条语句:
select dbId,dbContent,dbIsOver,Convert(char(10),dbDate,23) from mydaily
dbDate是字段名称。
原标题:dataGridView日期显示为短日期
关键词:GridView
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。