如何在gridview中计算时间格式? [英] How to compute time format in gridview?

查看:77
本文介绍了如何在gridview中计算时间格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gridview中有三列。

第一列和第二列有时间格式。例如:19:00 | 21:00

和第三列应该是第一和第二列的总时间。



我试过这个:



I have three columns in my gridview.
The first and second column has a time format . example : 19:00 | 21: 00
and on the third column should be the total time in the first and second column.

I tried this:

For i As Integer = 0 To gridview.Rows.Count - 1
               gridview.Rows(i).Cells(3).Text = gridview.Rows(i).Cells(0).ToString - gridview.Rows(i).Cells(1).ToString
           Next





但是它不起作用。

任何人都可以给我其他方式吗?

谢谢!



but it is not working.
Can anyone give me other way?
Thanks !

推荐答案

RowDataBound [ ^ ]事件计算每行的差异







返回与您的dataSource(数据库?)的区别,只是将列绑定到现有差异







使用jQuery







从服务器端代码计算中添加模板字段调用静态(或受保护)功能值

(例如:
In RowDataBound [^]event calculate the difference for each row

OR

Return the difference from your dataSource (database?) and simply bind the column to existing difference

OR

Use jQuery

OR

Add template field calling static (or protected) function from your server side code calculating the value
(example:
<asp:TemplateField HeaderText="Total" ItemStyle-HorizontalAlign="Center" >
   <ItemTemplate>
      <%# GetDifference((Eval("time2"), Eval("time1")) %>
   </ItemTemplate>
</asp:TemplateField>









在所有情况下,您必须使用DateDiff函数(存在于SQL Server中,其他数据库中必须存在等效函数)。也存在于.net ...选择你的解决方案。


)


In all the cases you have to use DateDiff function (exists in SQL Server, there must be equivalent in other databases). Also exists in .net... pick your solution.


你可以从SQL DB轻松完成



You can do it easily from SQL DB as

select right('00'+convert(varchar,datediff(HOUR,CONVERT(datetime,'18:00',103),CONVERT(datetime,'19:30',103))),2)
+':'+right('00'+
convert(varchar,datediff(MINUTE,CONVERT(datetime,'18:00',103),CONVERT(datetime,'17:30',103))),2)



如果有帮助请将其标记为答案


if it helps please mark it as answer


好的。我在这里找到了解决方案。它很容易。 MYSQL中的时差 [ ^ ]
Okay. I found the solution here. And it was so easy . TIME DIFFERENCE IN MYSQL[^]


这篇关于如何在gridview中计算时间格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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