我的列表会话未检索到正确的值

My list session is not retriving the right value

我有一个列表来保存客户选择的订单,我想将列表中的值传递给其他页面,所以我尝试使用

HttpContext.Current.Session["list"] = MySelected;

但我没有在其他页面中获取值。

订购页面:

protected void ButtonCreate_Click(object sender, EventArgs e)
{
    string MyPkList = string.Join(",", MySelected);    
    SqlCommand cmdSQLCount = new SqlCommand("select Count(*) from [EncomendaTEMP] where No_ IN(" + MyPkList + ")", con);
        cmdSQLCount.Connection.Open();
        int qtd = 0;
        SqlDataReader reader = cmdSQLCount.ExecuteReader();
        while (reader.Read())
            qtd = reader.GetInt32(0);
        if (qtd > 0)
        {
            HttpContext.Current.Session["list"] = MySelected;
            Response.Redirect("Booking.aspx", false);                
        }
        else
        {
            Response.Write("<h2> Nenhum registo encontrado! </h2>");
        }

预订页面:

protected void Page_Load(object sender, EventArgs e)
{
     var list = HttpContext.Current.Session["list"];
     Response.Write("<h2> PK = "+list+" </h2>");
}

returns:

要获取 List<string> 中元素的连接值,请尝试:

var list = HttpContext.Current.Session["list"] as List<string>; 
string items = string.Join(",", list);

来自@Chetan Ranpariya 的评论。