将数组存储到会话 [英] Storing array to session

查看:80
本文介绍了将数组存储到会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在会话中添加数组?有办法吗?继承我的代码:



 protected void CompetencyRetrieve(object sender,EventArgs e)
{
int index = Convert。 ToInt32(maxindex.Text); // ERROR HERE

DropDownList box1 =(DropDownList)Gridview1.Rows [index] .Cells [1] .FindControl(DropDownList1);
DropDownList box2 =(DropDownList)Gridview1.Rows [index] .Cells [2] .FindControl(DropDownList2);
DropDownList box3 =(DropDownList)Gridview1.Rows [index] .Cells [3] .FindControl(DropDownList3);

var Trainings = DataService.Instance.getTraining(box2.Text,box1.Text);
if(Trainings.Rows.Count!= 0)
{
box3.DataSource = Trainings;
box3.DataTextField =ProgramsDesc;
box3.DataValueField =Programs_id;
box3.DataBind();

//此处会话

}
其他
{
box3.Items.Clear();
}


}





每次这个功能触发器,将添加数组的条目,然后存储在会话中。任何帮助?

解决方案

试试这个

可能会对你有帮助..

存储所有物品数组。

  string  [] a =  new   string  [] {  a  b  c}; 
会话[ values] = a;



在下一页中,您可以像这样检索它。

  string  [] a =( string  [])会话[  


Hi,

how can I add an array to a session? is there a way to do it? heres my code:

protected void CompetencyRetrieve(object sender, EventArgs e)
   {
       int index = Convert.ToInt32(maxindex.Text); // ERROR HERE

           DropDownList box1 = (DropDownList)Gridview1.Rows[index].Cells[1].FindControl("DropDownList1");
           DropDownList box2 = (DropDownList)Gridview1.Rows[index].Cells[2].FindControl("DropDownList2");
           DropDownList box3 = (DropDownList)Gridview1.Rows[index].Cells[3].FindControl("DropDownList3");

           var Trainings = DataService.Instance.getTraining(box2.Text, box1.Text);
           if (Trainings.Rows.Count != 0)
           {
               box3.DataSource = Trainings;
               box3.DataTextField = "ProgramsDesc";
               box3.DataValueField = "Programs_id";
               box3.DataBind();

               //session here

           }
           else
           {
               box3.Items.Clear();
           }


   }



each time that this function triggers, an entry to the array will be added, then stored inside a session. any help?

解决方案

Try this
may be this will help you..
To store all items of the array.

string[] a = new string[]{"a","b","c"};
Session["values"] = a;


And in the next page, you can retrieve it like this.

string[] a = (string[])Session["values"]


这篇关于将数组存储到会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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