gridview,数据绑定,日期和格式问题 [英] gridview, databinding, date and formatting problem

查看:61
本文介绍了gridview,数据绑定,日期和格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


一个似乎很难解决的简单问题...


我有一个带有日期行的gridview。

< ItemTemplate>

< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" time")$ / b $ b%>''>< / asp:标签>

< / ItemTemplate>


我可以添加一些代码,只显示日期而不是时间吗?


祝你好运,

Stijn

Hi all,

A simple problem that seems hard to solve...

I have a gridview with a date row.
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("time")
%>''></asp:Label>
</ItemTemplate>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn

推荐答案


ta ****** @ gmail.com schreef:

ta******@gmail.com schreef:

大家好,


一个似乎难以解决的简单问题...


我有一个带日期行的gridview。

< ItemTemplate>

< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" time")$ / b $ b%>''>< / asp:标签>

< / ItemTemplate>


我可以添加一些代码,只显示日期而不是时间吗?


祝你好运,

Stijn
Hi all,

A simple problem that seems hard to solve...

I have a gridview with a date row.
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("time")
%>''></asp:Label>
</ItemTemplate>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn



似乎当你将此行更改为模板字段时

dataformat属性不再可用。不完全不逻辑

但是我可以格式化行的字符串让我们说theItemTemplate吗?

非常感谢任何帮助。

It seems that when you "change this row to a templatefield" the
dataformat property is not available anymore. Not entirely unlogical
but can I format the strings of the row for let''s say theItemTemplate?
Any help is greatly appreciated.


您可以在查询中设置日期格式,以

想要的格式返回日期。


如果使用SQL Server:CONVERT(DATETIME,YourField,1)


在我看来,根据需要返回数据要容易得多

在日期的情况下,发回你不需要的东西,然后格式化它。


ta * *****@gmail.com"写道:
You can format your date in your query to return the date in the format you
want.

If using SQL Server: CONVERT(DATETIME, YourField, 1)

In my opinion, it is much easier to just return the data as you want it then
to send back something you don''t need, in the case of a time on the date, and
then format it.

"ta******@gmail.com" wrote:

>
ta ***** *@gmail.com schreef:
>
ta******@gmail.com schreef:

大家好,


一个似乎难以解决的简单问题...


我有一个带日期行的gridview。

< ItemTemplate>

< asp:标签ID = QUOT; Label2的" RUNAT = QUOT;服务器" Text =''<%#Bind(" time")$ / b $ b%>''>< / asp:标签>

< / ItemTemplate>


我可以添加一些代码,只显示日期而不是时间吗?


祝你好运,

Stijn
Hi all,

A simple problem that seems hard to solve...

I have a gridview with a date row.
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("time")
%>''></asp:Label>
</ItemTemplate>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn



看来当你将此行更改为模板字段时

dataformat属性不再可用。不完全不逻辑

但是我可以格式化行的字符串让我们说theItemTemplate吗?

非常感谢任何帮助。


It seems that when you "change this row to a templatefield" the
dataformat property is not available anymore. Not entirely unlogical
but can I format the strings of the row for let''s say theItemTemplate?
Any help is greatly appreciated.


" Mike Collins" < Mi ********* @ discussion.microsoft.com写信息

news:89 ******************* *************** @ microsof t.com ...
"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.com...

您可以在查询中设置日期格式以返回日期格式为



想要。


如果使用SQL Server:CONVERT(DATETIME,YourField,1)


在我看来,只要你想要它就可以更容易地返回数据

然后

寄回你不喜欢的东西在日期的情况下,需要



然后格式化它。
You can format your date in your query to return the date in the format
you
want.

If using SQL Server: CONVERT(DATETIME, YourField, 1)

In my opinion, it is much easier to just return the data as you want it
then
to send back something you don''t need, in the case of a time on the date,
and
then format it.



我完全不同意。


首先,SQL Server中的CONVERT函数有一个相当有限的

日期选项的数量 - 当然没有像.NET中的.ToString()方法可用的丰富性。


其次,实际上并不是数据库层的工作是提供

格式化 - 这是表示层的。更好的,IMO,让SQL

Server将本机数据返回到GUI(通过业务层,

根据需要)并让GUI控制如何显示数据......

I disagree totally.

For one thing, the CONVERT function in SQL Server has a fairly limited
number of options for dates - certainly nothing like the richness that is
available with the .ToString() method in .NET.

Secondly, it really isn''t the job of the database layer to provide
formatting - that''s for the presentation layer. Much better, IMO, to let SQL
Server return the native data to to the GUI (through the business layer(s),
as required) and let the GUI control how that data is displayed...


这篇关于gridview,数据绑定,日期和格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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