如何从数据库获取数据时只显示GridView控件中的日期? C# [英] How to display only date in GridView when pulling data from a DB? C#

查看:134
本文介绍了如何从数据库获取数据时只显示GridView控件中的日期? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个访问数据库中提取数据,在ASP.NET项目GridView控件来显示。它工作正常,但我想看看我是否能格式,被拉的数据。目前,任何货币正在从XX.XX截断只是美元金额。另外,日期显示为MM / DD / YYYY HH / MM / SS AM / PM

I am pulling data from an access database to show in a GridView control on a ASP.NET project. It works fine but I want to see if I can format the data that is being pulled. Currently any currency is being truncated from xx.xx to just the dollar amounts. Also the dates are displaying mm/dd/yyyy hh/mm/ss AM/PM

我试过编辑数据库本身正确的价值观(我设定的货币字段为货币和日期字段为短日期,但是当我拉在该日期仍显示他们没有格式化。

I tried editing the database itself to the right values (I set the currency field to "Currency" and the date field to "Short Date" but when I pull that date it still shows them not formatted.

编辑:不好意思,只好拿code下来

Sorry, had to take the code down

任何想法?
谢谢

Any ideas? Thank you

推荐答案

在你的网格视图中添加所谓的财产 DataFormatString

in the grid view of yours add the property called DataFormatString

DataFormatString例子:



{0:dd MMMM yyyy}    -    gives 24 February 2006
{0:MMM dd}          -    gives Feb 24 (substitue MMM with MMMM for the full month name 
                         instead of abbreviation) 
{0:dd/MM/yy}        -    gives 24/02/06 
{0:dd/MM/yyyy}      -    gives 24/02/2006

样品code

<asp:BoundField HeaderText="Date" 
                DataField="SampleDate" 
                DataFormatString="{0:MM/dd/yyyy}"  >

这篇关于如何从数据库获取数据时只显示GridView控件中的日期? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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