Results 1 to 6 of 6

Thread: [RESOLVED] Restoring an entire listbox from a session variable

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Resolved [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
    William E Gollnick

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    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.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    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
    William E Gollnick

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    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
    William E Gollnick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width