您的位置:首页 > 其它

使用ViewState[""]传递Hashtable的值

2016-03-26 19:25 197 查看
//首先定义
Hashtable myHach = new Hashtable();

//添加键值到Hashtable中
myHash.Add("ServiceType1", "值");

//例:
myHash.Add("Account1", this.txtAccount1.Text.Trim());

//把Hashtable放入ViewState[""]里
ViewState["condition"] = myHash;

//取得Hashtable的值
Hashtable ht = (Hashtable)ViewState["condition"];

//判断Hashtable中是否存在对应键
if(ht.ContainsKey("ServiceType1"))

//如果存在就把值赋给字符串
string ServiceType1 = ht["ServiceType1"].ToString();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: