如何在视图状态中保存数组?并在ASP.NET中检索它?

时间:2012-02-18 04:04:08

标签: asp.net viewstate

我正在使用Asp.Net和JqueryMobile(C#)。我声明string [] roomno = new string [100];在我的课堂上。

Page_load活动中: -

if (!Page.IsPostBack)
{
    Some Code...
     for (int j = 0; j <= vallen; j++)
     {
         roomno[j] = "A" + Convert.ToString(j + 1);
     }
    Some Code,..
}

单击按钮时数组值清除。 所以我想知道如何在View State中保存数组?并在ASP.NET中检索它?

2 个答案:

答案 0 :(得分:4)

ViewState["some_key"] = roomno;

roomno = ViewState["some_key"] as string[];

或者说这样的话:)

答案 1 :(得分:0)

ViewState["SomeKey"] = (string[])roomno;
roomno = (string[])ViewState["SomeKey"];

或初始化

string[] roomno = string[0]; 
ViewState.Add("SomeKey", roomno);