Dropdown Selection Lost on Listbox Sort

Scott

I'm using 2 listboxes and transferring items between the two. I have an item template on the destination listbox with a label and a databound dropdownlist. I move items to the destination LB, then choose a selection for each dropdown item. If I then transfer another item from source LB to destination LB, the dropdown selections are all lost (selected index becomes 0 again).
The issue lies in the sort itself, because if I comment out the sort method, the dropdowns retain their selection after a transfer.
Here is the listbox item transferred event code I'm using. If I comment out the first 4 lines of the method, the selections are retained. The foreach statement is apparently required in order to make the items in the itemtemplate display properly.

Peter Filipov

I wasn't able to create a sample project from the description below. Could you please provide a working sample project that reproduces your issue to investigate it locally.

All the best,
Peter Filipov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward!
We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Scott

I was able to reproduce it in a small sample project. I'll just post the code here since there's not much to it. If you try this code, the dropdown selections don't persist after postback but if you comment out the sorting code and try it again, the dropdown selections are retained after postback.

Peter Filipov

Thank you for the provided sample code. I created a sample project based on it. Also I was able to reproduce your issue. It happens, because the sort method is called too early in the page life cycle.

Please find attached the fixed files.

All the best,
Peter Filipov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward!
We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Scott

This corrected the issue when I transfer items to the source listbox, however, when I do any other postback the selections are still lost. I have 3 source/destination listboxes on this page, and all 3 post back on transfer. When I transfer one of the other listboxes, the dropdown selections are still lost on this one.

Scott

Nevermind, I figured it out. It's kind of sloppy, but I checked to see if the transfer button for this listbox was clicked in the page load. If it was, then I set a flag to true. I then added a check for this flag before going into the sorting loop. So basically it only sorts the list if the associated transfer button was clicked. Thanks again.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.