Add Rows to Dynamically generated table

I have a table that I am building dynamically depending on a specified number of rows set by the user. What I want to do is to add more rows if they need more. For example I will have a button on the form that says add 10 more rows. I need to add these rows at the bottom of the already generated table. The CreateTable() function below is what first builds the table based on a number of rows the user specified. The btnSubmit_Click() event handler would append the additional 10 rows. I tried using  tblThrows.Rows.AddAt(?,tr); but when I do a row count it is only returning 1, it does not see the dynamically generated rows.  Any help would be greatly appreciated.
public void CreateTable(int Rows)
    {
 
        for (int i = 1; i <= Rows; i++)
        {
            TableRow tr = new TableRow();
            TableCell td = new TableCell();
            TableCell td1 = new TableCell();
            TextBox txtTicketsWon = new TextBox();
 
            txtTicketsWon.ID = i + "_TicketsWon";
            txtTicketsWon.Attributes.Add("onblur", "AddTickets()"); 
 
            tr.ID = i + "_Row";
 
            td.BorderWidth = 1;
            td.BorderStyle = BorderStyle.Solid;
            td.BorderColor = Color.Black;
 
            td1.BorderWidth = 1;
            td1.BorderStyle = BorderStyle.Solid;
            td1.BorderColor = Color.Black;
 
            td.Text = i.ToString();
            td1.Controls.Add(txtTicketsWon);
            tr.Cells.Add(td);
            tr.Cells.Add(td1);
 
            tblThrows.Rows.Add(tr);
            RowCount += 1;
        }
 
    }
 
    public void btnSubmit_Click(object o, EventArgs e)
    {
 
        int Count = tblThrows.Rows.Count;
        
        for (int i = 0; i <= 10; i++)
        {
            TableRow tr = new TableRow();
            TableCell td = new TableCell();
            TableCell td1 = new TableCell();
            TextBox txtTicketsWon = new TextBox();
 
            txtTicketsWon.ID = i + "Additional_TicketsWon";
 
            td.BorderWidth = 1;
            td.BorderStyle = BorderStyle.Solid;
            td.BorderColor = Color.Black;
 
            td1.BorderWidth = 1;
            td1.BorderStyle = BorderStyle.Solid;
            td1.BorderColor = Color.Black;
 
            td.Text = i.ToString();
            td1.Controls.Add(txtTicketsWon);
            tr.Cells.Add(td);
            tr.Cells.Add(td1);
 
            tblThrows.Rows.AddAt(?,tr);
        }
 
    }

Open in new window

LVL 3
pablo_munozAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I would suggest refactoring the code within the for loop in the CreateTable, and call that method to add to the table.

Bob
0
pablo_munozAuthor Commented:
           for(var i = 0; i < 10; i++)
            {
                var tbl = document.getElementById('tblThrows');
                var lastRow = tbl.rows.length;
               
                // if there's no header row in the table, then iteration = lastRow + 1
                var iteration = lastRow;
                var row = tbl.insertRow(lastRow);

                // left cell
                var cellLeft = row.insertCell(0);
                var textNode = document.createTextNode(iteration);
                cellLeft.style.border = "1px solid #000000";
                cellLeft.appendChild(textNode);

                // right cell
                var cellRight = row.insertCell(1);
                var el = document.createElement('input');
                el.type = 'text';
                el.name = 'txtRow' + iteration;
                el.id = 'txtRow' + iteration;
                el.size = 20;

                el.onblur = AddTickets;
                cellRight.style.border = "1px solid #000000";
                cellRight.appendChild(el);
            }  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.