if(e.CommandName=="AddToBus")
{
string shoeID=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
SqlConnection con=DB.createCon();
con.Open();
SqlCommand cmd=new SqlCommand("select shoePhoto from shoe where shoeID='"+shoeID+"'",con);
string shoePhoto=Convert.ToString(cmd.ExecuteScalar());
if(Session["bus"]==null)
{
System.Collections.Hashtable ht=new Hashtable();
ht.Add(shoePhoto,1);
Session["bus"]=ht;
Response.Write("<script language='javascript'>alert('您已经将该鞋放入了购物车!');</script>");
}
else
{
System.Collections.Hashtable ht=(Hashtable)Session["bus"];
if(ht[shoePhoto]==null)
{
ht[shoePhoto]=1;
}
else
{
ht[shoePhoto]=(int)ht[shoePhoto]+1;
}
Session["bus"]=ht;
Response.Write("<script language='javascript'>alert('您已经将该鞋放入了购物车!');</script>");
}
}上头为我session的创建过程
请问我如何将session中的所有内容写成个字符串
比方说赋值给Label1.Text

解决方案 »

  1.   

    string str=Label1.Text;
    Session["str"]=str;
      

  2.   


    if(Session["bus"] != null)
       this.Label1.Text = Session["bus"].toString();
      

  3.   

      string aa = null;
            Hashtable ht = new Hashtable();
            ht["鞋子"] = 3;
            ht["内裤"] = 4;
            ht["卫生巾"] = 6;
            ht["避孕套"] = 20;
            foreach (System.Collections.DictionaryEntry obj in ht)
            {
                aa += obj.Key.ToString() + obj.Value.ToString()+"<br/>";
            }
            this.Label1.Text = aa;
      

  4.   

    string strKeys = "";
    string strValue = "";
    if(Session["bus"] != null)
    {
       Hashtable ht = (Hashtable )Session["bus"];
       IDictionaryEnumerator enumerator = ht.GetEnumerator();
       while (enumerator.MoveNext())
       {
          strKeys += enumerator.key.Tostring();
          strValue += enumerator.Value.Tostring();
       }
    }
    --这里看你想要什么值
    label.Text = strKeys;--名称
    label.Text = strValue ;--数量