Solved

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

Posted on 2011-02-26
5
733 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now