behzad
behzad

Reputation: 43

How can add to Session without erase previous value in asp.net?

I'm new in asp.net want to add value to session without erase previous value,write this code:

 Session["behzadList"] = BookIDI.Trim();


but that code when run erase previous value and add it to Session,i want when run that code add new value end of previous value a thing like array in c#,i have to use Session and don't want any other way,thanks all.

Upvotes: 0

Views: 256

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460238

You can store a List<string> in session:

List<string> behzadList = Session["behzadList"] as List<string> ?? new List<string>();
behzadList.Add(BookIDI.Trim());
Session["behzadList"] = behzadList;

Upvotes: 2

Related Questions