hi,

i want to store a arraylist in a session variable & retrieve it on the other page. how it can be done..

for example,

ArrayList ar = new ArrayList();

        ar.Add("a");
        ar.Add("b");

        Session["id"] = ar;

now how can i retrieve the arraylist on the other page?

i tried

arraylist ar=session["id"]

but its not working.

plz help me..its really urgent.

Recommended Answers

All 2 Replies

You have to cast the session first. Following is an example:

ArrayList ar = new ArrayList();
            ar.Add("A");

            Session["id"] = ar;
            Response.Write("Item Count="+((ArrayList)Session["id"]).Count.ToString());
ArrayList ar=Session["id"] as ArrayList;

or

ArrayList ar=(ArrayList)Session["id"];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.