|
-
Dec 31st, 2011, 03:41 PM
#1
Thread Starter
Hyperactive Member
[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
-
Jan 2nd, 2012, 01:37 AM
#2
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).
Last edited by sapator; Jan 2nd, 2012 at 01:42 AM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 5th, 2012, 02:26 AM
#3
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
-
Jan 5th, 2012, 05:52 AM
#4
Thread Starter
Hyperactive Member
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
-
Jan 5th, 2012, 06:01 AM
#5
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
-
Jan 5th, 2012, 08:48 PM
#6
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|