If an item is not selected, only way it can be maintained across postbacks is with the help of viewstate. Since you are adding these items on the clientside, they are not part of the viewstate when you postback, so the server has no idea about this., so you should send them some how to the server
And if the item is not selected, it wouldnt be part of Form posted data. So, in your case there is no simpler way unfortunately.
May be you should consider using some hidden input control and write these items as a string to this hidden input control and send back to server and iterate through this string to retrieve the values. Once the values go back to the server, they would be part of the viewstate, if its enabled for the listbox, right before the page is show to you. So, postbacks from then onwards would maintain these values even if they are not selected
As has been mentioned, you'll have to store these values in a hidden form field or somewhere for retrieval on postback when you can insert them into the list's Items collection.
Some links you may find helpful (these are pre-fab solutions):
DynamicListBox
DualList
EasyListBox
Cheers,
Thanks for the ideas. I think I will go with the hidden field.
0 comments:
Post a Comment