0

I'm trying to add some rows to a table control in my updatepanel. I have a button in update panel and when the button is clicked, partial postback happens, in button_click handler I add 1 row to the table. I can trigger the postback event and I am able to add 1 row each time, but the problem is that every time the page is postedback I got the initial table, meaning all the rows I've added in previous postbacks are gone, how can I solve this? Any ideas are welcome?

4

1 回答 1

1

When you add rows in the table, you also need to save the struck of the table and somewhere else, for example on the view state, or on a database, or somewhere, and then recreate it because the code behind and the page it self did not have "a memory for what you do" on a table, did not know what you do on the DOM in general.

You may see the table on the page, but when you make a post back, the code behind did not get the post back of the struck of the table, only the posted data from input controls, so did not know by default what you have done on the table, and renders it from the beginning.

So, if you won to add rows in a table, and you won to remembers them on the next post back, save your struct also somewhere else, and when I say your struct, I do not mean all the table, you can simple save a number, eg how many rows you have add, or a number and an id, how many rows and what is on every row, and then before you add new rows, and on every post back, you recreate the table.

于 2012-07-19T07:20:53.357 回答