Link to home
Start Free TrialLog in
Avatar of ThePrettyGeek
ThePrettyGeekFlag for United States of America

asked on

adding multiple rows to a table dynamically via vb.net and ASP.net

OK so, Im trying to add data to a table that will eventually be exported to a database and I know there must be a for each statement added to this Im just not sure exactly how to do this. This is what I have thus far. It adds one line to the table but forgets it as soon as go to add anothert line.
 I set up tablelist as a string array but Im not sure how to use it to do a "for each" in it to reconstruct the table when the page goes to its ispostback and should I add the code to the ispostback section in the page load sub.. I know Im on the right track but Im missing somethign stupid.

Here is my code

    Private Sub AddDataAndTableRow()

        Dim tr As New TableRow
        WorkTable.Rows.Add(tr)
        tr.Height = 25
        Dim td1 As New TableCell
        Dim td2 As New TableCell
        Dim td3 As New TableCell



        Try

            Do Until CurrentColumnCount = 4


                If CurrentColumnCount = 1 Then
                    td1.Text = txtbox1.Text
                    TableList(CurrentColumnCount - 1, CurrentRowCount - 1) = td1.Text
                    tr.Cells.Add(td1)
                    CurrentColumnCount = CurrentColumnCount + 1
                ElseIf CurrentColumnCount = 2 Then
                    td2.Text = Convert.ToString(chkbox.Checked)
                    TableList(CurrentColumnCount - 1, CurrentRowCount - 1) = td2.Text
                    tr.Cells.Add(td2)
                    CurrentColumnCount = CurrentColumnCount + 1
                ElseIf CurrentColumnCount = 3 Then
                    td3.Text = txtbox2.Text
                    TableList(CurrentColumnCount - 1, CurrentRowCount - 1) = td3.Text
                    tr.Cells.Add(td3)
                    CurrentColumnCount = CurrentColumnCount + 1

                    'CurrentRowCount = WorkTable.Rows.Count

                Else
                    CurrentColumnCount = 1
                End If

                If CurrentRowCount < 1 Then

                End If


            Loop


        Catch ex As Exception
        End Try

    End Sub
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

how many textboxes are you getting your data from?

I work out 2 textboxes and a checkbox (only).

QN: What do you want to loop through?
Avatar of dreamkey
dreamkey

Are your trying to dynamically create the html table structure and populate it with input controls first, then read those values back in after the postback?

Your code sample looks like you are attempting to do both at once.
Avatar of ThePrettyGeek

ASKER

Yes there are just two text boxes and a checkbox that go into the table however there are a couple of other textboxes that are being added to the array so the array however many rows and 6 columns but the table is only 3 columns.
The headers for the columns are already hard coded into the web page and they show up and when I add one line it shows up but I need it to remember the old data when I add a new line or, re-create the old data when I add a new line.
ASKER CERTIFIED SOLUTION
Avatar of ThePrettyGeek
ThePrettyGeek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Figured it out myself