如何在会话中存储2D字符串数组? [英] How to store 2D string array in a session?

查看:58
本文介绍了如何在会话中存储2D字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个2D字符串数组,它正在从数据库中检索数据.问题是,当我单击按钮时,由于重新加载,数组变空.我需要将其存储在会话中或以其他任何方式存储.

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;

我认为我在Session中存储的只是数组的基地址.

I think what I'm storing in the Session is just the base address of the array.

我希望将所有数据存储在Session中.如果你们有解决此问题的想法或以不同方式存储字符串表的任何其他想法,对我真的很有帮助.

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()); 
}

这篇关于如何在会话中存储2D字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆