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. Web Development
  3. ASP.NET
  4. How to pass & retrieve gridview as session variable.

How to pass & retrieve gridview as session variable.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasesysadminhelp
7 Posts 3 Posters 3 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.
  • A Offline
    A Offline
    ashutosh_karna
    wrote on last edited by
    #1

    Hello Friends, I am new to asp.net , so please help me out. I have made a small gridview ( without any database connectivity) on page(Default.aspx). The user fills up one of the column with numeric data & clicks a button & control is transferred to another page(Results.aspx). Can anybody tell me how can I pass the whole gridview as session varaible & then retrieve it in another page & further retrieve the column filled up by the user. Code in "Result.aspx" protected void Page_Load(object sender, EventArgs e) { DataView dv1 = new DataView(); DataTable dt1 = new DataTable(); Session["A"] = dv1.Table.Columns["A"]; } protected void TextBox1_TextChanged(object sender, EventArgs e) { // double[] data = new double[Session["A"]]; // WRONG CODE . PLEASE CORRECT IT // WRITE CODE FOR RETRIEVING COLUMN THAT USER HAS FILLED UP IN GRIDVIEW IN default.aspx } Code in "Default.aspx" : protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("NewPage.aspx"); // HOW TO PASS GRIDVIEW ALONG WITH USER DATA }

    I N 2 Replies Last reply
    0
    • A ashutosh_karna

      Hello Friends, I am new to asp.net , so please help me out. I have made a small gridview ( without any database connectivity) on page(Default.aspx). The user fills up one of the column with numeric data & clicks a button & control is transferred to another page(Results.aspx). Can anybody tell me how can I pass the whole gridview as session varaible & then retrieve it in another page & further retrieve the column filled up by the user. Code in "Result.aspx" protected void Page_Load(object sender, EventArgs e) { DataView dv1 = new DataView(); DataTable dt1 = new DataTable(); Session["A"] = dv1.Table.Columns["A"]; } protected void TextBox1_TextChanged(object sender, EventArgs e) { // double[] data = new double[Session["A"]]; // WRONG CODE . PLEASE CORRECT IT // WRITE CODE FOR RETRIEVING COLUMN THAT USER HAS FILLED UP IN GRIDVIEW IN default.aspx } Code in "Default.aspx" : protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("NewPage.aspx"); // HOW TO PASS GRIDVIEW ALONG WITH USER DATA }

      I Offline
      I Offline
      Ibrahim Bello
      wrote on last edited by
      #2

      //Default.aspx protected void Button1_Click(object sender, EventArgs e) { Session["A"] = GridView1.Columns["A"]; Server.Transfer("NewPage.aspx"); } //Result.aspx protected void Page_Load(object sender, EventArgs e) { GridViewColumn col = (GridViewColumn)Session["A"]; GridView2.Columns.Add(col); }

      N 1 Reply Last reply
      0
      • A ashutosh_karna

        Hello Friends, I am new to asp.net , so please help me out. I have made a small gridview ( without any database connectivity) on page(Default.aspx). The user fills up one of the column with numeric data & clicks a button & control is transferred to another page(Results.aspx). Can anybody tell me how can I pass the whole gridview as session varaible & then retrieve it in another page & further retrieve the column filled up by the user. Code in "Result.aspx" protected void Page_Load(object sender, EventArgs e) { DataView dv1 = new DataView(); DataTable dt1 = new DataTable(); Session["A"] = dv1.Table.Columns["A"]; } protected void TextBox1_TextChanged(object sender, EventArgs e) { // double[] data = new double[Session["A"]]; // WRONG CODE . PLEASE CORRECT IT // WRITE CODE FOR RETRIEVING COLUMN THAT USER HAS FILLED UP IN GRIDVIEW IN default.aspx } Code in "Default.aspx" : protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("NewPage.aspx"); // HOW TO PASS GRIDVIEW ALONG WITH USER DATA }

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

        ashutosh_karna wrote:

        how can I pass the whole gridview as session varaible

        You don't want to do that. GridView is just a presentation of the data. You don't pass textboxes and other such controls between pages do you? Allow the users to fill in the data, save it, then transfer to the next page, retrieve the data and present it on that page. In anticipation of the line of thought, no you don't want to save the DataSet, or whatever storage object you are using, in session state either. A DataSet can take quite a bit of memory depending on what is in it, it wouldn't scale very well.


        only two letters away from being an asset

        I 1 Reply Last reply
        0
        • N Not Active

          ashutosh_karna wrote:

          how can I pass the whole gridview as session varaible

          You don't want to do that. GridView is just a presentation of the data. You don't pass textboxes and other such controls between pages do you? Allow the users to fill in the data, save it, then transfer to the next page, retrieve the data and present it on that page. In anticipation of the line of thought, no you don't want to save the DataSet, or whatever storage object you are using, in session state either. A DataSet can take quite a bit of memory depending on what is in it, it wouldn't scale very well.


          only two letters away from being an asset

          I Offline
          I Offline
          Ibrahim Bello
          wrote on last edited by
          #4

          The code above actually saves the data in a session. If he doesn't want to do the saving in the first page better save data into a Session and retrieve in the second page. Less burden on the Database too.

          N 1 Reply Last reply
          0
          • I Ibrahim Bello

            //Default.aspx protected void Button1_Click(object sender, EventArgs e) { Session["A"] = GridView1.Columns["A"]; Server.Transfer("NewPage.aspx"); } //Result.aspx protected void Page_Load(object sender, EventArgs e) { GridViewColumn col = (GridViewColumn)Session["A"]; GridView2.Columns.Add(col); }

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

            :wtf: :rolleyes: You don't store presentation objects and pass them around. Have you even tried this? I doubt it very much


            only two letters away from being an asset

            1 Reply Last reply
            0
            • I Ibrahim Bello

              The code above actually saves the data in a session. If he doesn't want to do the saving in the first page better save data into a Session and retrieve in the second page. Less burden on the Database too.

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

              Ibrahim Bello wrote:

              Less burden on the Database too.

              And when the data being stored in session is large or the number of concurrent users is high?


              only two letters away from being an asset

              I 1 Reply Last reply
              0
              • N Not Active

                Ibrahim Bello wrote:

                Less burden on the Database too.

                And when the data being stored in session is large or the number of concurrent users is high?


                only two letters away from being an asset

                I Offline
                I Offline
                Ibrahim Bello
                wrote on last edited by
                #7

                No, surely not :) If that is the case (and he hasn't said whether it is) saving to database will be better.

                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