tags:

views:

58

answers:

3

Hi,

I have a gridview control on the page. when the page is loaded for the first time i am binding the data to the grid. But on the client side user can copy a row and add below in the grid. So iam doing it using jquery $(CpRow).clone(true).insertAfter(CpRow). But when the page is postback the clientside added row is lost due to viewstate.

how can i update the gridview view state so that the row is not lost in further postbacks.

Thanks in advance...

+1  A: 

The long and short of it is that there is no simple way to do this. I'm surprised you are even able to postback without getting an invalid viewstate error given that the controls collection (via Request.Form) won't match the viewstate.

If you're not getting invalid viewstate issues, you may be able to store the IDs of the rows you have cloned in a hidden field and do some processing of these IDs on Postback to re-add the cloned rows on the server. This will ensure the cloned rows have their values stored in viewstate correctly.

Hope this helps, apologies if it's a vague answer - like I said, there are no simple solutions with regard to this problem.

Paul Suart
+1  A: 

The view state has to be created on the server side. To change the grid and have it survive the post back, you have to change the grid through some sort of an asp.net postback/asp.net ajax post.

Kevin
or is there any way to convert the HTML row string to grid view row control?
BABA
not without doing a postback and adding the row on the server side.
Kevin
A: 

Hi,

The problem is solved, i used hidden variables to store the cloned rows at the server and once the postback happens i am re binding the grid with new rows added.

Thanks 4 the answers..

BABA
Glad to help, cheers.
Paul Suart