C# 存取Session值

 //存入Session
    protected void Button1_Click(object sender, EventArgs e)
    {
        string[] str = new string[] { "A", "B", "C", "D" };
        Session["str"] = str;
       Session["ds"] =Class1.ExecuteDataset("Data Source=.;Initial Catalog=northwnd;User ID=sa;Password=123", "select * from product", CommandType.Text, null);
    }


    //获取Session
    protected void Button2_Click(object sender, EventArgs e)
    {
        object o = Session["str"];
        string[] str =(string[])o;
        foreach (string item in str)
        {
            Response.Write(item + "<br>");
        }
        GridView1.DataSource = (DataSet)Session["ds"];
        GridView1.DataBind();
    }


版权声明:本文为u014424282原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。