Iam Using Session to pass values to another Page. Iam using ArrayList in Session.
In next page am deleting some list items
In Session["ContrcatList"] i have around 20 items and i delete some items based on contractId which is unique for each item in array list, but when i again use Session["ContractList"] this get modified(ArrayList after deletion of some items) and i dont get the orginal value. How i will get original value and i need 2 modify Array list as well.
ArrayList listOfContract = null;
listOfContract = (ArrayList)Session["ContractList"]; // here listOfContract.Count = 20
ArrayList ar1 = new ArrayList();
ar1 = listOfContract;
ar1[0] = listOfContract[contractId];
ar1.RemoveRange(1, ar1.Count - 1);
ArrayList listOfContract1 = null;
listOfContract1 = (ArrayList)Session["ContractList"]; // here listOfContract.Count = 1;
Sam HobbsPosted Apr 16, 2011, 6:26 PM
- Sets listOfContract to null
- Gets listOfContract from ContractList in the session
- Sets ar1 to a new ArrayList
- Sets ar1 to the ArrayList from the session, so the new ArrayList is wasted
- Replaces the first item of ar1
- Removes everything in ar1 except the first one; ar1 is the same ArrayList as listOfContract
- Creates listOfContract1 and sets it to null
- Sets listOfContract1 to the ArrayList ContractList in the session which is the same ArrayList as listOfContract and the same one that got all items except the first removed
Does that explain what is happening?Vishwas KadamannayaPosted Apr 16, 2011, 2:16 AM
Yes in this i modify the ArrayList but i dont know how its getting Effected to the Session which has arraylist variable.
Suthish NairPosted Apr 14, 2011, 9:59 AM
This line removes all the values expect first on zeroth index.
Put a breakpoint and check each line and found out why its getting failed.