Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep updating Session object with a List<string> in c#

Status
Not open for further replies.

tsisher

Programmer
Sep 14, 2004
36
GB
I have a Session object

Session["MyListObjects"] = null;

When a user hits a button I want to creat a List<string> object and add to session object.

Let's say if user hits the button 10 times, I would get 10 List<string> ojects and add to Session["MyListObjects"]
and

Finally I want to read all the List<string> objects from the session object.

Please let me know how to do that.
Thanks,
 
Code:
class MyPage : Page
{
  List<List<string>> Lists
  {
      get 
      {
         if(Session["key"] == null)
         {
           Session["key"] = new List<List<string>>();
         }
         return (List<List<string>>)Session["key"];
      }
  }

  //wired to the button click event that creates lists
  void AddAnotherList(object sender, EventArgs e)
  {
     Lists.Add(new List<string>());
  }
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks Jason Meckley.

At some point I have to extract values from all the list in the session object. How can I do that?
Many thank again.
 
iterate over the list.
Code:
foreach(var list in Lists)
{
  foreach(var value in list)
  {
     ...
  }
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top