I have a ListBox with data bound to a List<> of Objects. On ListBox_SelectionChanged event, I am checking whether the selected index is the last item of the List<>. If the selectedIndex is the last item, then I want to remove the item and call my web service to add more items to the list. But if the selectedIndex is not the last item, the I want to navigate to a page. My problem is if the selectedTndex is the last item, it goes and remove the last item but it again comes back to the same “if” condition again where I check if the selectedIndex is the last item. So, instead of call my service, it navigates to the next page. Can anybody tell me why is it calling the if() condition again and how to handle it?
I have a ListBox with data bound to a List<> of Objects. On ListBox_SelectionChanged
Share
I think that when you remove your item from listbox he (ListBox control) automatically selects previous item, and this fires SelectionChanged event. So you can just unsubscribe from this event before (in pseudocode):
So when you will remove your item this event will not fire again. Also, may be you will want to clear selection: