我想添加一个session [i'],其中更多结果
当前仅显示一组结果
例如。School1 11/10/2011 14/11/2011 GCSE AAA
我想添加更多集,但似乎没有存储在会话中
例如。
School111/11/2011 14/11/2011 GCSE AAA
school22012 11/10/2012 Alevels AAA
Education addResults = new Education(schoolName, fromDate, toDate , qualification , grades);
Session["i"] = (addResults );
//schoolarraylist.Add(addResults );
foreach (Education currentschool in schoolarraylist)
{
Session["i"] = currentschool.Schoollocation + "," + currentschool.Datefrom + "," + currentschool.Dateto + "," + currentschool.Qualifications + "," + currentschool.Grade + "<br />";
string tmp = Session["i"].ToString();
string[] sb = tmp.Split(',');
string [] ii = new string[sb.GetUpperBound(0) + 1];
for (int i = 0; i <= sb.GetUpperBound(0); i++)
{
ib[i] = (sb[i]);
}
foreach (string j in ii)
{
Response.Write(ii);
}
}
您可以将对象列表分配给session,然后将其恢复。But you should not put data in seesion without need
。会话在每个用户的服务器端维护,并且将数据放入会话中需要存储服务器,并且可能会降低应用程序的性能。它值得阅读有关会话之前的阅读。
List<string> lst = new List<string>();
Session["i"] = lst;
从Session Object获取列表。
List<string> lst = (List<string>)Session["i"];
问题是,您将某些内容分配给session [" i"],当您尝试在会话中添加某些内容时,您实际上覆盖了先前的值。为了在会话中添加对象,您要么必须选择另一个名称,例如session [" j"]或在对象周围包裹某种容器(列表,数组,字典等),然后将该容器存储在您的会话中。
还要尝试为会话找到更好的名称,如果您以后查看代码,您可能不会知道会话[" i"]实际上应该是。
<</p>您也可以使用arraylist:
ArrayList list = new ArrayList();
foreach (Education currentschool in schoolarraylist)
{
list.Add(currentschool.Schoollocation + "," + currentschool.Datefrom + "," + currentschool.Dateto + "," + currentschool.Qualifications + "," + currentschool.Grade)
}
然后循环浏览阵列列表,并以WhateCver格式显示您要显示