How to pass & retrieve gridview as session variable.
-
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 }
-
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 }
//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); }
-
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 }
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
-
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
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.
-
//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); }
: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
-
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.
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
-
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
No, surely not :) If that is the case (and he hasn't said whether it is) saving to database will be better.