当其他值更改时,在GridView中计算一个值 [英] Calculating a value in GridView when other values change
问题描述
我正在VB.NET ASP.NET页面上使用GridView.
当用户编辑一行并更改Time In或Time Out值时,我需要重新计算Total Hours值并为其填写.
SQL表实际上将总小时数"存储为字段,即使它是根据超时"和超时"来计算的.
用户需要编辑和更改超时"或超时",该页面需要填写小时数.
我正在努力做到这一点.我知道我该如何使用Windows窗体,但是在ASP.NET中,EditTemplate中的Textbox似乎没有相同的事件,而且我不知道如何从另一个EditTemplate中更改Textbox的值.比事件被解雇了.
任何帮助将不胜感激.
I''m working with a GridView on a VB.NET ASP.NET page.
When the user edits a row and change the Time In or Time Out value, I need to recalculate the Total Hours value and fill it in for them.
The SQL table actually stores the Total Hours as field even though it''s calculated from the Time In and Time Out.
The page needs to fill in the hours anytime the user edits and changes the Time In or Time Out.
I am struggling with doing this. I know how I''d do it with Windows forms, but in ASP.NET the Textbox in the EditTemplate doesn''t seem to have the same Events and I can''t figure out how to change the Textbox value from another EditTemplate than the event was fired.
Any help would be greatly appreciated.
推荐答案
好像我没有记错,您正在尝试根据用户输入的登录和注销时间来获取花费的总小时数.因此必须在gridview的行更新"命令中进行计算.
请点击以下链接计算小时值:
http://www.dotnetspider.com/resources/458-How-find-difference-between-two-Dates-C-or.aspx [ http://stackoverflow.com/questions/4946316/showing-difference-在两个小时之间的时间值 [ ^ ]
-AK
Hi,
As if I am not wrong you are trying to get the total number of hours spend based upon the login and log out time entered by the user. So calculation has to done in Row Update command of gridview.
Please follow the link below to calculate the hour value:
http://www.dotnetspider.com/resources/458-How-find-difference-between-two-Dates-C-or.aspx[^]
http://stackoverflow.com/questions/4946316/showing-difference-between-two-datetime-values-in-hours[^]
-AK
如果您使用数据集加载gridview,则它只有一个方法数据集.已更改返回您在该gridview中所做的总更改,您可以将其与旧数据进行比较或执行您需要的任何过程
if you load gridview with dataset then it have one method dataset.Haschanged return you the total change done in that gridview which you can campare with old data or do any process that u need
我能够弄清楚如何创建总计
I was able to figure out how to create the totals
Dim colTotals(7) As Decimal, rowTotal As Decimal, pageTotal As Decimal
Dim boxBind As TextBox, labelBind As Label
Dim boxValue As Decimal, boxString As String
For Each row As GridViewRow In GridViewTimeSheet.Rows
rowTotal = 0
For col As Integer = 1 To 7
boxBind = row.FindControl("TextBoxHours" + col.ToString())
If (Not boxBind Is Nothing) Then
boxString = boxBind.Text
Else
labelBind = row.FindControl("LabelHours" + col.ToString())
boxString = labelBind.Text
End If
If (Decimal.TryParse(boxString, boxValue)) Then
colTotals(col) = colTotals(col) + boxValue
rowTotal = rowTotal + boxValue
pageTotal = pageTotal + boxValue
End If
Next
labelBind = row.FindControl("TotalHours")
labelBind.Text = rowTotal.ToString("0.00")
Next
For col As Integer = 1 To 7
GridViewTimeSheet.Columns(col * 4 + 4).FooterText = colTotals(col).ToString("0.00")
Next
GridViewTimeSheet.Columns(33).FooterText = pageTotal.ToString("0.00")
这篇关于当其他值更改时,在GridView中计算一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!