Loop Through ASP Table Object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LacrosseB0ss
    New Member
    • Oct 2006
    • 112

    Loop Through ASP Table Object

    I have a table object (not html, or database table, <asp:Table>) on my form that has data in it. When the user clicks a "Submit" button on a form, I would like to loop through this table row by row picking up the information in it and writing it to the database.

    I was using the code below but I got an error (invalid index or something) @ the line tblTable.Rows(i ).Cells(j).Text . Can anyone help please?

    Code:
    ASP:
    For i = 1 To tblTable.Rows.Count 'exclude header row
    			For j = 1 To numCols 'I don't need the 1st column
    				empArray(j) = CStr([B]tblTable.Rows(i).Cells(j).Text[/B])
    			Next j
    			strList &= strArray(1) & " - " & strArray(2) & ", "
    		Next i
    I'm still trying to figure this out so some of the style sucks due to not knowing entirely what's going on. Thanks in advance

    - LB
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by LacrosseBoss
    I have a table object (not html, or database table, <asp:Table>) on my form that has data in it. When the user clicks a "Submit" button on a form, I would like to loop through this table row by row picking up the information in it and writing it to the database.

    I was using the code below but I got an error (invalid index or something) @ the line tblTable.Rows(i ).Cells(j).Text . Can anyone help please?

    Code:
    ASP:
    For i = 1 To tblTable.Rows.Count 'exclude header row
    			For j = 1 To numCols 'I don't need the 1st column
    				empArray(j) = CStr([B]tblTable.Rows(i).Cells(j).Text[/B])
    			Next j
    			strList &= strArray(1) & " - " & strArray(2) & ", "
    		Next i
    I'm still trying to figure this out so some of the style sucks due to not knowing entirely what's going on. Thanks in advance

    - LB
    Hi. How is the empArray declared?
    Also what is the strArray and why are the exact same values being assigned to strList numCols times?

    Comment

    • LacrosseB0ss
      New Member
      • Oct 2006
      • 112

      #3
      sorry, they are strings.

      I figured out what the problem was. I have a header row for my table and nothing else until the code populates it with employees that are read from a listbox on another form. From this form (where the table is) a button is clicked to submit information or make changes.

      When the "Submit" button is clicked, all information is written to the database. However, the form is also posted back and the Table Rows don't stick around. So, when it hit the line Table.Rows(1).C ells(1).Text, it doesn't exist and the error is produced.

      I've since changed the code and now when a row is added to the table, the employee being added is also added to a String array of all employees. I will input this array into the database (unless there's a way to NOT postback the form, or to not lose the table's rows/data).

      Thanks for your help
      - LB

      Comment

      Working...