简体   繁体   English

在会话中存储ArrayList值

[英]Storing ArrayList value in Session

I have a particular problem regarding the Session["arr3"] and an ArrayList: " arr3 ". 关于Session [“ arr3”]和ArrayList:“ arr3 ”,我有一个特殊的问题。

I have stored certain values in Session["arr3"] , and upon the click event of a button eg ' btnSpclins_Click ', I want to assign the Session["arr3"] the following values:- 我已经在Session [“ arr3”]中存储了某些值,并且在按钮的单击事件(例如' btnSpclins_Click ')上,我想为Session [“ arr3”]分配以下值:

Session["arr3"] = Session["arr3"] + arr3; Session [“ arr3”] =会话[“ arr3”] + arr3;
But I am recieving the following compilation error:- 但是我收到以下编译错误:
Operator '+' cannot be applied to operands of type 'object' and 'System.Collections.ArrayList' 运算符“ +”不能应用于类型为“对象”和“ System.Collections.ArrayList”的操作数

Or I may make it simple as:- 或者我可以简化为:
Session["arr3"] += arr3; 会话[“ arr3”] + = arr3;
This is causing the following compilation error:- 这导致以下编译错误:
"Operator '+=' cannot be applied to operands of type 'object' and 'System.Collections.ArrayList'". “运算符'+ ='不能应用于类型为'object'和'System.Collections.ArrayList'的操作数”。


OBJECTIVE : The objective to do this is to hold the Session["arr3"]'s values (this is what I am referring to old value of Session["arr3"] ), and then add the ArrayList arr3's values to the Session["arr3"], and then these two combined values ( Session["arr3"] + arr3) are then stored in the Session["arr3"]. 目的 :这样做的目的是保存Session [“ arr3”]的值(这是我指的Session [“ arr3”]的旧值),然后将ArrayList arr3的值添加到Session [ “ arr3”],然后将这两个组合值(Session [“ arr3”] + arr3)存储在Session [“ arr3”]中。 Now this will be the new Session["arr3"]'s value. 现在,这将是新Session [“ arr3”]的值。 This value will be saved/inserted in a DB Table. 此值将保存/插入数据库表中。


I want to retain the old value of Session["arr3"], and add the old value with the arr3(ArrayList) value and save in the Session["arr3"]. 我想保留Session [“ arr3”]的旧值,并使用arr3(ArrayList)值添加旧值并保存在Session [“ arr3”]中。 And this final Session["arr3"] value is inserted in a Database's Table. 最后的Session [“ arr3”]值插入数据库的表中。

Please help me in this aspect at earliest. 请尽早在这方面帮助我。

If I understand correctly, you have an existing ArrayList in session. 如果我理解正确,则会话中已有一个ArrayList。 You also have a new ArrayList called arr3 and you want to join them together, storing the result back in the session. 您还拥有一个名为arr3的新ArrayList,并且希望将它们连接在一起,并将结果存储回会话中。

If so, you need to cast your session object back to what it is before appending the new elements: 如果是这样,则需要在附加新元素之前将会话对象转换回原来的状态:

Session["arr3"] = ((ArrayList)Session["arr3"]).AddRange(arr3);

This will take the original ArrayList from the session, append the elements in arr3, and put it back in the session. 这将从会话中获取原始ArrayList,将元素添加到arr3中,然后将其放回会话中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM