比如说session["user"]里面放有数据,我怎么才能把这里的数据读出来赋给label的text。麻烦把代码写的详细点,本人新手。

解决方案 »

  1.   


    if(Session["user"]!=null)
    {
      Label1.Text=Session["user"];
    }
      

  2.   


    像上图我点了登录后label里面有用户名显示,而我跳到另一个页面时就变成这样了要怎么设置代码才能要这个一样,不管跳到哪个页面都能显示
    以下是我在button_click加的代码
    string username = this.username.Text;
                string userpwd = this.password.Text;
                Session["success"] = "flase";
                if (username == "" || userpwd == "")
                {                Response.Write("<script language=javascript>alert('用户名和密码不能为空');</script>");
                }
                else
                {
                    DataAccess myData = new DataAccess();
                    DataSet ds = myData.ulogin(username,userpwd);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        
                        Session["user"] = username;
                        Session["upwd"] = ds.Tables[0].Rows[0]["password"].ToString();
                        Session["success"] = "true";
                        label1.Text = Session["user"].ToString();
                    }
                    else
                    {
                        Response.Write("<script language=javascript>alert('用户名或密码不正确');</script>");
                        this.username.Text = "";
                        this.password.Text = "";
                        this.username.Focus();
                    }
                }
      

  3.   

    Label1.Text="欢迎您:"+(Session["user"]==null?"":Session["user"].ToString());
      

  4.   

    在page_load的if(!ispostback){}中写3L的代码
      

  5.   

    if(!ispostback){Label1.Text="欢迎您:"+(Session["user"]==null?"":Session["user"].ToString());
    }