面临问题。同时将数据从excel文件上传到datagrid视图 [英] facing prob. while upload data from excel file to datagrid view

查看:80
本文介绍了面临问题。同时将数据从excel文件上传到datagrid视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将数据从excel文件上传到数据网格视图时遇到了问题。

Excel包含列''s $



名称

联系号码

地址

父亲的名字

来自地方

放置

时间

date

当数据在数据网格视图中加载时,时间列显示数据,如30-12- 1899 PM 12:20:00



但实际数据是下午12:20:00我不知道为什么这个日期30- 12-1899是时间????



帮帮我解决这个问题???

解析方案

我怀疑你用来加载gridview的数据库是时间字段的数据类型日期时间。如果是这样的话,只能从你在excel中想要的gridview中的时间字段中获取一部分。



 < asp:BoundField  DataField =date1HeaderText =Date < span class =code-leadattribute> of 保留SortExpression =date
DataFormatString ={ 0 dd / MM / yy} />





DataFormatString例子:

{0:dd MMMM yyyy} - 给出2006年2月24日

{0:MMM dd} -gives 2月24日(用MMMM取代MMM的全月名称)而不是缩写)

{0:dd / MM / yy} -gives 24/02/06

{0:dd / MM / yyyy} -gives 24/02 / 2006



您可以查看 this 链接,以获取有关如何使用dataformatstrings的进一步参考。


在Excel中更改日期和时间列格式



Examble

I have been facing problem while upload data from excel file to datagrid view.
Excel contain column''s as

name
contact no
address
father''s name
from place
to place
time
date
when ever data get load in datagrid view the time column shows data like "30-12-1899 PM 12:20:00"

but actual data is PM 12:20:00 and i dont why this date "30-12-1899" is came up time????

Help me to sort out this problem???

解决方案

I suspect the database that you use to load your gridview have a datatype datetime for time field .If so,get only part from the time field in gridview that you want in your excel.

<asp:BoundField DataField="date1" HeaderText="Date Of Leave" SortExpression="date"
                            DataFormatString="{0:dd/MM/yy}" />



DataFormatString examples:
{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

You can have look at this link for further reference on how to use dataformatstrings.


Change ur Date and time column format in Excel

Examble


这篇关于面临问题。同时将数据从excel文件上传到datagrid视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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