Hi,
Here we may need to know before we continue solving the issue that why the additional row can be added at the first time, but falls to be added later.
When framework rendering the page, it just displays what we wrote in HTML source and what we hoped to be changed by the behind-code. That means, when the first time we want to add the row, framework render the original table first and then, add a row according to our code. But the next time we hope to add another new row, framework has no idea about the previous row we had already created. It just, like what it always does, displays the HTML source, where the original table with the original row count is, and then, add one row according to the code.
That is the reason why we cannot add the second, third and more new row to the table. Have a read at this FAQ may help you more to understand this issue: FAQ: Why do dynamic controls disappear on postback and not raise events?.
Then, let's focus on what we need to do. Since we can already create rows by a loop and a ViewState storing the rowunmber, the problem now is how to set the TextBox's value after postback.
Based on the solution vinz producted, I suggest you following the block below to modify the code around Line 56.
TextBox tb = new TextBox();
tb.ID = "TextBoxRow_" + i + "Col_" + j;
//here, please add this if statements to set the value of the TextBox
if (Request.Form["TextBoxRow_" + i + "Col_" + j] != null)
{
tb.Text = Request.Form["TextBoxRow_" + i + "Col_" + j];
}
cell.Controls.Add(tb);
row.Cells.Add(cell);
Best Regards,
Shengqing Yang
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )