Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Casting a session object to a generic object

Casting a session object to a generic object

Scheduled Pinned Locked Moved C#
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swiftain
    wrote on last edited by
    #1

    Lets say you have code block like this public void BindGridData(IEnumerable result) { Session["result"] = result; gridView.DataSource = result; gridView.DataBind(); } How do you call this function in another event passing the Session["result"] as the argument? How do you cast Session["result"] back to the generic object? thanks

    N K 2 Replies Last reply
    0
    • S Swiftain

      Lets say you have code block like this public void BindGridData(IEnumerable result) { Session["result"] = result; gridView.DataSource = result; gridView.DataBind(); } How do you call this function in another event passing the Session["result"] as the argument? How do you cast Session["result"] back to the generic object? thanks

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You have already asked this in your previous post, please don't repeat it.


      I know the language. I've read a book. - _Madmatt

      S 2 Replies Last reply
      0
      • N Not Active

        You have already asked this in your previous post, please don't repeat it.


        I know the language. I've read a book. - _Madmatt

        S Offline
        S Offline
        Swiftain
        wrote on last edited by
        #3

        What do you mean by that? who made you moderator of the site??

        P 1 Reply Last reply
        0
        • N Not Active

          You have already asked this in your previous post, please don't repeat it.


          I know the language. I've read a book. - _Madmatt

          S Offline
          S Offline
          Swiftain
          wrote on last edited by
          #4

          If you don't have a meaningful contribution to make, then you should be quiet.

          N 1 Reply Last reply
          0
          • S Swiftain

            Lets say you have code block like this public void BindGridData(IEnumerable result) { Session["result"] = result; gridView.DataSource = result; gridView.DataBind(); } How do you call this function in another event passing the Session["result"] as the argument? How do you cast Session["result"] back to the generic object? thanks

            K Offline
            K Offline
            kevinnicol
            wrote on last edited by
            #5

            Sesion returns genaric objects, you have to cast them.

            MyDataType result = Session["result"] as MyDataType;

            N S 2 Replies Last reply
            0
            • S Swiftain

              If you don't have a meaningful contribution to make, then you should be quiet.

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              I think you should take a deep breath before responding. If you want to get pissy about being told of the conventions and expectations of this community then perhaps you should step away for a bit. You have been given assistance on your problem, don't spoil it with such an attitude.


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              • K kevinnicol

                Sesion returns genaric objects, you have to cast them.

                MyDataType result = Session["result"] as MyDataType;

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                How bloody obvious :rolleyes: Now perhaps you'd like to actually read the OP's question.


                I know the language. I've read a book. - _Madmatt

                1 Reply Last reply
                0
                • K kevinnicol

                  Sesion returns genaric objects, you have to cast them.

                  MyDataType result = Session["result"] as MyDataType;

                  S Offline
                  S Offline
                  Swiftain
                  wrote on last edited by
                  #8

                  Thanks for the response, but the data type is a generic data type as shown form the code I originally posted. The session object has a generic object of IEnumerable type, so how would I cast back to that generic type?

                  1 Reply Last reply
                  0
                  • S Swiftain

                    What do you mean by that? who made you moderator of the site??

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    There are a couple of very valid reasons for Marks reply to you. The most important reason is that it becomes very difficult to track answers if multiple threads are spawned about the same topic. Bear in mind that the question may be viewed, in the future, by others who want to know the answer to the problem; the search engines will point them to one thread. Churn and growth of other threads could mean that they end up not seeing the whole picture because the vital part of the answer is now in another thread. Now, take a deep breath and relax.

                    I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                    Forgive your enemies - it messes with their heads

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups