Solved

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

Posted on 2011-02-26
5
736 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:ThePrettyGeek
  • 3
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 34988892
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?
0
 

Expert Comment

by:dreamkey
ID: 34989756
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.
0
 

Author Comment

by:ThePrettyGeek
ID: 34989956
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.
0
 

Accepted Solution

by:
ThePrettyGeek earned 0 total points
ID: 35014750
I fixed this by doing a redim of the array variable with preserve included in the statement to keep all the old data then I was able to keep all the old data and add to the array. After that it was a simple thing of moving the data from the array and adding rows to the table until the table row count was the same as the row count in the array.

All I got was questions no even partial answers on this one. But this would be the solutions in simplified terms...
0
 

Author Closing Comment

by:ThePrettyGeek
ID: 35045729
Figured it out myself
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question