1

I have a repeater in my page with some pre-conditions such as a checkbox list and listboxes that dictate what the datasource for the repeater brings back. A button is clicked which will databind the repeater which works fine. However if the user decides they want to add something else in or remove something they can check/uncheck some fields and then hit the button again which will rebind the repeater and change what is displayed, however the viewstate of all the current controls in the repeater will be lost.

Binding the repeater in the initialization event would not be possible because the ViewState for the checkboxlist/listbox values are not available at that point in the page lifecycle, and those values are required in order to pass as parameters into my datasource for the repeater.

What are my options for maintaining the state of my repeater controls?

1 Answer 1

1

repeater control binding fully recreates all of children controls inside repeater templates. Because new DataBind result may (or may not) contains extremely different data inside repeater. What kind of controls and their state you want to maintain inside repeater? Maybe using ordinal html controls and operating with theirs through Request.Form collection would be a better way?

If you want to save data from repeater before applying new databinding, best place for making it is a Page.PreRender event. In this event all Page controls already recreated and their viewstate already restored. So you may iterate by Repeater.Items collection and save data from repeater row by row. And after saving all the data you may rebind repeater controls according current filter values from page.

7
  • Heres a screenshot: imgur.com/4y6rb8m They are basically all textboxes, a couple rows have dropdownlists in a column further down not visible in the image. But I will note there is a nested repeater. Each of parent repeater rows such as "Visa" has an inner repeater which shows multiple child rows. But I just need to maintain the values of those textboxes.
    – cpiasecki
    Nov 20, 2013 at 20:39
  • Ok, and how you want to associate old textboxes/DDL, returned with form submit with new, created after repeater rebinding? Or you want firstly process data changes in repeater and after that rebind it? Nov 20, 2013 at 20:44
  • I just want to ensure any of the groups that are still there in the newly created repeater still have their values in the textbox. There are quite a few fields for the user to enter in, so if halfway they realized they forgot to include one of the groups or they decided they dont need one they want to be able to check/uncheck one of the boxes and then regenerate the repeater, but they dont want to lose all those values and have to start over again.
    – cpiasecki
    Nov 20, 2013 at 20:51
  • Ok, lets imagine simple situation. after loading your repeater has, for example, 5 items with 5 textboxes. User has filled those textboxes and has made some filter changes, after which your repeater actually has 2 others items. so how you plan to deal with this? Maybe better way will be to save all data from Repater on each postback and after that databind? Nov 20, 2013 at 21:01
  • I add description where and how you may save data from repeater before applying filters. Nov 20, 2013 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.