We are using List<object> type as datasource for dropdownlist.
Process flow:
- Assign value (
List<object>) to the session in the pageload event(!ispostback). - Retrieve value from session in
ddl_SelectedIndexChangedevent - Remove a particular item from the list and bind to the ddl
Code:
List<Loc> locList = new List<Loc>();
locList = (List<Loc>)Session["Loc"];
locID = "xxx";
locList.RemoveAt(locList.FindIndex(FindLocation));
Problem:
Item is getting removed from the base source also (session).
The problem is that you’re manipulating the list that is stored in the session, not a copy. Instead, if you do something like this:
you’re operating on a copy of the list, and the original won’t change.