[RESOLVED] Restoring an entire listbox from a session variable
In my opening page of a web app I create (from a database get) two somewhat large datasets for 2 listboxes. I populate and databind them and all is good with the world
I then want to take those 2 listbox datasets and put them into a session variable for use on other pages of the web app. The reason is I do not want those additional hits in populating the two listboxes again (data does not change)
I am calling a class and passing back a DATASET for each listbox .. then
Session (DATASET_1) = MyClass.Dataset1
Session (DATASET_2) = MyOtherClass.DataSet2
DATASET_1 AND DATASET_2 are defines as constants with a type of DS
When I attempt to rebind the listboxes as
ListBox1.DataSource = Session( DATASET_1 ) *AS System.Data.DataSet ListBox.DataBind()
and the same deal for listbox 2 nothing happens........
Make sense??
gollnick
Re: Restoring an entire listbox from a session variable
Not much.Why are you putting an entire dataset to session is one question.
Another is and i can't remember now but anyhow, will a dataset bind to a listbox just like that (i mean i think you need it's datatable but again not sure without a PC to check it).
Also another question is what is DATASET_1 and DATASET_2?Are they strings?If not then you are doing something strange.Session variables to my knowledge are named key-strings.Again i wouldn't pass an entire dataset to session.Just the values i need.Better yet on the new page i would have populated the dataset's again and not stored them to session(aka unnecessary reserved server memory usage,unless if you are storing session to a database that i don't think you do or is necessary in your case).
Re: Restoring an entire listbox from a session variable
Hello,
I have to agree with Sap here. If actually all you are using is a DataTable, then that is what you should return from your method to store in the Session Variable.
Also, bear in mind that every Session variable is actually stored as an Object, so when you retrieve it from the Session variable, you really should re-cast it back to the correct type, before assigning it to the DataSource property.
Also, once you set the DataSource, I am fairly sure that you need to call the DataBind() method. Are you doing this elsewhere in your code?
Gary
Re: Restoring an entire listbox from a session variable
Yes .. BUT I changed direction and casting it back as a listbox object and assigning it to an application session variable. Then binding it directly back to my user interface listbox. Thanks
gollnick
Re: [RESOLVED] Restoring an entire listbox from a session variable
Sounds like you have a solution, however, in order to be sure, can you show the code that you now have working?
Gary
Re: [RESOLVED] Restoring an entire listbox from a session variable
The solution works great for combo boxes and list boxes alike so it must work OK, and yes an application session is a much smaller packet to worry about