I gave that a shot, but that didn't do it. I'm still only getting one new row. Also to clarify, this is not a "gridview" and I'm not working with any data that's getting bound. Thanks for time and suggestion.
Main Topics
Browse All TopicsI'm trying to click a linkbutton and have more rows added to a table via server side code. I will adding controls that I can iterate through later. Every time the link button it clicked, I want another NEW row to be added. However, when clicked... one new row is added, but that's it. When clicked again, it seems that the row is that is just added is lost and the same row is re-added. ViewState not being enabled doesn't seem to be the problem, as I have it enabled ever where I can think of. Maybe my understanding of how postback and viewstate works is incorrect. I would expect that when you have a session on the server and viewstate enabled that when a control is dynamically added via postback, it would persist until you leave the page. Anyone have any ideas? I'm sure someone has come across this before.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Dynamically created controls must be re-created on each postback see : http://www.singingeels.com
Since you add the table row and then next postback you dont re-add the one you already added, it wont get re-created.
You could create list held in view state, something like :
public List<string> Items
{
get {return this.ViewState["Items"] ?? new List<string>();
set {this.ViewState["Items"] = value;
}
then in your button click do something like
List<string> lst = this.Items;
lst.Add("New Item");
this.Items = lst;
then override CreateChildControls and do something like
foreach (string str in this.Items)
{
TableCell NewCell = new TableCell();
TableRow NewRow = new TableRow();
NewCell.Text = String.Format("Added Cell {0}",str);
NewRow.Cells.Add(NewCell);
MyTable.Rows.Add(NewRow);
}
Since I was only concerned with a single table. This is what I ended up doing. I saved the table to a session variable session variable which is nice cause it saves everything in the table. I set a temp table to the session saved table or if that doesn't exists to the table on the page. I make all the modifications to that, then place it back in the page and save to the session variable. This works exactly like I wanted it to.
Business Accounts
Answer for Membership
by: ged325Posted on 2009-07-01 at 07:53:49ID: 24754965
After the rows.Add
MyTable.DataBind();
DataBind syncs up the changes.