Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-26
5
Medium Priority
?
758 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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