Solved

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

Posted on 2011-02-26
5
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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