在不使用外部数据库的情况下存储会话的数据

本文关键字:情况下 存储 会话 数据 数据库 外部 | 更新日期: 2023-09-27 18:30:52

我正在为基于团队的游戏创建一个Web应用程序。这是场景:

    1. First we enter the participants ID. After entering an ID 
       the user clicks save button and the same is displayed in a gridview below. 
       This way we enter multiple IDs and all of them are added in the gridview.
    2. Then we click shuffle and the inserted IDs are shuffled.

我已经有了第二部分的逻辑。但是我无法一个接一个地存储ID。我想知道存储该会话 ID 的最佳方法是什么。我不想使用任何外部数据库。我尝试过列表、数组、字典、数据表等,但一旦用户插入 ID 并单击保存,页面就会重新加载,新数据会覆盖旧数据,并且网格视图中只显示一个 ID。谁能提出实现这一目标的最佳方法?

在不使用外部数据库的情况下存储会话的数据

您可以

创建ID的ArrayList并将其保存在Session

ArrayList Al=new ArrayList();
if(Al.Indexof("23"))         // check items already exists
Al.Add("12");                //adding items
Al.Add("13");
Al.Add("14");
Al.Remove("12")        //remove item
Session["myId"]=Al;

取回

if(Session["myId"]!=null)
ArrayList Al=  (ArrayList) Session["myId"];
else
ArrayList Al=new ArrayList();
相关文章: