Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Maciej Los 4-May-12 13:43pm    
TextBox in Web.UI.WebControls have TextChanged event. Use it ;)

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
 
Share this answer
 
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
 
Share this answer
 
I was able to figure out how to create the totals

VB
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")
 
Share this answer
 
Comments
Maciej Los 10-May-12 11:51am    
Is this a question or is this an answer?

If any above solution was helpful, please, rate it and mark as "solved".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900