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

问题描述 投票:3回答:2

我正在使用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中检索它?

asp.net viewstate
2个回答
4
投票
ViewState["some_key"] = roomno;

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

或者说那个效果:)


0
投票
ViewState["SomeKey"] = (string[])roomno;
roomno = (string[])ViewState["SomeKey"];

或者初始化

string[] roomno = string[0]; 
ViewState.Add("SomeKey", roomno);
© www.soinside.com 2019 - 2024. All rights reserved.