Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I reference subsequent rows in datagrid? :)

Status
Not open for further replies.

mikemardon

Programmer
May 23, 2005
71
GB
I have a datagrid in which I need to perform calculations on a postback event row-by-row until the row number = 50 .

I have written the formula for row 1 which works fine but I need to find a way of getting the next row into this sub so I can apply a modified formula to it (and every other successive row until row 50).

Can anyone offer any advice on how I should go about this?

-----------------------------------------------------------
Here is my code for the sub :
-----------------------------------------------------------

Dim tb As TextBox = CType(sender, TextBox)
Dim item As DataGridItem = CType(tb.NamingContainer, DataGridItem)
Dim YearNumber As Integer = (item.ItemIndex + 1)
Dim TextBoxValue As Integer = tb.Text
Dim myrr As New ReversionRow
Dim Cell0 As String = "100"
Dim Cell1 As String = CType(item.Cells(1).Controls(1), Label).Text
Dim Cell2 As String = CType(item.Cells(2).Controls(1), TextBox).Text
Dim Cell3 As String = CType(item.Cells(3).Controls(1), TextBox).Text
Dim Cell4 As String = CType(item.Cells(4).Controls(1), TextBox).Text
Dim Cell5 As String = CType(item.Cells(5).Controls(1), TextBox).Text
Dim Cell6 As String = CType(item.Cells(6).Controls(1), TextBox).Text
'convert to correct data type (int or decimal)
Dim col0 As Decimal = CDec(Cell0)
Dim col1 As Integer = CInt(Cell1)
Dim col2 As Integer = CInt(Cell2)
Dim col3 As Integer = CInt(Cell3)
Dim col4 As Integer = CInt(Cell4)
Dim col5 As Decimal = CDec(Cell5)

Dim Var1 As Decimal
Dim Var2 As Decimal
Dim Var3 As Integer
Dim Index As Integer

If Session("RYear") Is Nothing Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'YEAR 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Session("RYear") = 1
Index = 1

If Session("RYear") = 1 Then
Index = Session("RYear")
myrr.PercentOfOriginal = 100.0
myrr.ReversionOfOriginal = col2
myrr.AddExtension = col3
myrr.UnitsExtended = col4

'ITBS
Var1 = ((col2 + (col3 * 100)) - (col4 * 100)) 'get the value of ITBS
Response.Write("% ITBS is : " & Var1)

Dim Var4 As String
Var4 = (col2 / 100)

myrr.PercentRemaining = "100"
myrr.PercentRemaining = ((myrr.PercentRemaining - Var4) + (col3 - col4))
Response.Write("Here : " & myrr.PercentRemaining)
myrr.ReversionYear = 1
Session("RYear") = 2
Session("PValue") = myrr.PercentRemaining
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SUBSEQUENT ROWS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'How can I make the next datagrid row the current item in scope?
ElseIf Session("RYear") > 1 And Session("RYear") < 50 Then
Response.Write("Fell off end!")
Response.Write("Next Year is : " & Session("RYear"))
Response.Write("Percentage is : " & Session("PValue"))

' 'subsequent rows
myrr.PercentOfOriginal = Session("PValue")
myrr.ReversionYear = Session("RYear")
'myrr.ReversionOfOriginal =


End If


-----------------------------------------------------------
 
What event are you performing this code? If you do this in the ItemDataBund event, it will fire for each row, which is what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top