I am developing an application using the gridview. the last column is a total column I want to compare the typed in value to the sum of values in the rest of the cells. I tried to use custom validation but the textboxes that contain the values are not seen by the application below is my validation code
I have also tried JavaScript which works fine if the user navigates through all the other cells but if not it does not work
Please help
Code:
Protected Sub validateTotals(ByVal source As Object, _
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) _
Dim total, sums As Integer
Dim txtBox As TextBox
sums = 0
txtBox = CType(GridView1.FindControl("Textbox1"), TextBox)
total = CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox1"), TextBox)
sums += CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox2"), TextBox)
sums += CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox3"), TextBox)
sums += CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox4"), TextBox)
sums += CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox5"), TextBox)
sums += CInt(txtBox.Text)
txtBox = CType(GridView1.FindControl("Textbox6"), TextBox)
sums += CInt(txtBox.Text)
If sums <> total Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
I have also tried JavaScript which works fine if the user navigates through all the other cells but if not it does not work
Please help