I have this 2D string array which is retrieving data from a database. Problem is, when i click a button, the array gets empty due to reload. I need to store it in a session or with any other way you guys suggest.
//Declaration in the class
string[,] randomizedOptionalTable;
//In the function of retrieving the database
randomizedOptionalTable = new string[qIDSize, 4];
//Database retrieving code.
Session["keyRandomizedOptionalTable"] = randomizedOptionalTable;
I think what I'm storing in the Session is just the base address of the array.
I want the entire data to be stored in the Session. It would really help me if you guys have a solution for this or any different idea to store a string table with different way.
Check the sample, working for me...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ToSession();
FromSession();
}
}
private void ToSession()
{
string[,] strTo2D = { {"A"}, {"B"} };
Session["str2DArray"] = strTo2D;
}
private void FromSession()
{
string[,] strFrom2D = (string[,])Session["str2DArray"];
Response.Write(strFrom2D[0, 0].ToString());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.