Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can´t add more than a row to a table

Status
Not open for further replies.

gcastillo

Programmer
Jun 9, 2000
127
MX
Hello. I have a HTML table, and in a row a table(from web forms). I have 2 cells, with a textbox each. I have a link button that needs to add a new row with the two cells and the two textboxes every time it's clicked. It works as expected the first time, but in subsequents clicks it only keeps the first row added!! The data I'm using is not from a database, so I dont use datagrids. The button link is to add dinamically new rows in the table. My code:

Private LinkButton_Click(...the usual)
For i = 1 To 1
Dim tRow As New TableRow
For j = 1 To 2
Dim tCell As New TableCell
tRow.Cells.Add(tCell)
tCell.Text = i & " - " & j
tblTest.Rows.Add(tRow)
Next
Next
End sub

I don't write the code for the textboxes, because that is not the real problem :-/
I have readed the thread855-1083548 but I can't make it work and I don't think it is exactly the same problem I have. Thank you in advance for your help

 
As you are adding the rows dynamically, they need to be added on the load of every page.

What I suspect is happening in your case is:

1) Page Loads for the first time
2) User Clicks the Add button to Add Row 1
3) Page Load event fires
4) Your code fires and Row 1 is added via the LinkButton_Click event
5) User Clicks the Add button to Add Row 1
6) Page Load event fires, however as you are not adding Row 1 in this event, it doesn't get created.
7) Your code fires and Row 2 is added via the LinkButton_Click event

So, you'll see that each row needs to be added on the load of every page as Row 1 isn't being generated in step #6 as you want it to be.




____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanx,ca8msm and yes, I think that something like that is happening, however, I tought that on every page load the status of my table would be preserved. I mean, if my page is on the browser with one row (the default), and I click the "Add new row" button, the page loads and the table now has TWO rows (it's happening as expected). If I click the "Add new row" button again, the page reloads and I was expecting that the table now would have THREE rows (not happening, only the last two rows appears)... Ok, if at the second reload the page doesn't keep the status of my modified table, how could I keep that status, and tell the page that the table now has two rows instead of the original one? I've been moving and writing the "is postback" and "EnableViewState" for all my code, but the output is the same :-/
Thank you!
 
I tought that on every page load the status of my table would be preserved
No, this is incorrect (the original table will be preserved but any dynamically added rows will not). Any dynamic controls will have to be created on every page load. Basically, you'll have to preserve the rows (i.e. ViewState, Session, Cache etc) and create them each time.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, ca8msm. I got it now... I finally could use the code that stsuing writes in the thread855-1083548. It works very fine, but not with a table with headers. Because the deadline for my project I'm using two tables, one with the headers and the other kept in a session var. I'll take a deep look later to fully understand how it's working =). If somebody have a different approach, or if you could help me telling me how I can keep the "modified state" of my table every load, it would be great. Thank you again¡ =)
 
And one final question! When I add a row, with the text boxes, and I write something in the textboxes, when I add a new row, in the page reload my text is gone!. I think that the structure of the table is kept in the session var, but how can I keep the text wrote in the textboxes?. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top