Reputation: 1471
I want to store list of data into session object. My scenario is I have one gridview control inside a page. below of the gridview have two text boxes and button. When i press button than gridview will have filled with text boxes value. Every time my pressing on button it will add new row into gridview to show entered data..So, for that i have to use session context. But my issue is how to store two textboxes value into session and how to read it again.. I dont want to use temporary sql database table.
So if anyone knows about it than please help me.. Thanks in advance.
Upvotes: 1
Views: 1670
Reputation: 1482
Try this :
Use this code on the click event of button
if(Session["value1"] == null)
{
Session["value1"] = new List<String>();
}
((List<String>)Session["value1"]).Add(testbox1.value);
To output the data you can loop through all the values :
List<String> V = (List<String>) Session["value1"];
for(int j = 0 ; j < V.Count ; j++)
{
String str = V[j];
//ADD str TO GRID VIEW.....
}
The same code goes for textbox2.
Upvotes: 1