gridview中的日期列显示12.00 AM时间 [英] Date Column in gridview shows 12.00 AM time

查看:104
本文介绍了gridview中的日期列显示12.00 AM时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview的一列中显示日期。我已经以编程方式绑定了我的gridview,即使用后面的代码。

数据库中相应的列数据类型为Date,但仍显示11/23/2013 12:00:00 AM。如果我在数据库中执行该程序,那么

显示11/23/2013。但是在gridview中它显示时间,即使数据库中没有时间。

请帮忙。

I am displaying date in one of the column in my gridview . I have binded my gridview programmatically i.e using code behind .
The corresponding column data type in the database is Date , but still it displays 11/23/2013 12:00:00 AM . If I execute the procedure in the database it
shows 11/23/2013 . But in the gridview it shows time too even though the time is not there in the database.
Please help .

推荐答案

在你的选择中查询转换日期,

例如:

从表中选择转换(varchar,datecolumn,105)。

注意:你可以改变105到其他数字以获得不同的日期格式(105将给你dd-MM-yyyy格式)。
In your select query cast the date,
example :
select convert(varchar,datecolumn,105) from table.
note: you can change the 105 to other number to get in different date format (105 will give you dd-MM-yyyy format).


how-to-set-date-format-in-gridview.html [ ^ ]



根据您的需要检查并格式化..
how-to-set-date-format-in-gridview.html[^]

Check this and format according to your need..


当我们从数据库中获取数据时,数据将作为对象返回。因此,在绑定到网格之前,您需要将值转换为字符串并指定日期格式,然后绑定数据,如Convert.ToDateTime(data).ToString(dd / mm / yyyy)
when we fetch the data from database the data will be returned as object. So before binding to the grid u need to convert the value to string and specify the date format and then bind the data like Convert.ToDateTime(data).ToString("dd/mm/yyyy")


这篇关于gridview中的日期列显示12.00 AM时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆