62,046
社区成员
发帖
与我相关
我的任务
分享
private Hashtable htResult = new Hashtable();
private Hashtable htTemp = new Hashtable();
private void AddV(string[] 数组)
{
for (int i = 0; i < 数组.Length; i++)
{//遍历选中的警员进行分析
if (!htTemp.ContainsKey(数组[i].ToString()))
{
Hashtable ht = Session["B"] != null ? Session["B"] as Hashtable : new Hashtable();
//查看下Session["B"]的内容
htTemp.Add(数组[i].ToString(), 数组[i].ToString());//不存在就添加
Hashtable ht1 = Session["B"] != null ? Session["B"] as Hashtable : new Hashtable();
//查看下Session["B"]的内容
}
}
Session["A"] = htTemp;//Session["A"]保存临时的哈希表
}
//最终的值保存在Session["B"]中
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="添加到listbox" />
<asp:Button ID="Button2" runat="server" Text="最终确定添加到listbox的内容"
onclick="Button2_Click" />
<asp:Button ID="Button4" runat="server" onclick="Button4_Click"
Text="取消(恢复到上去确定)" />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="283px" Width="207px">
</asp:ListBox>
</form>
</body>
private Hashtable httemp;
private Hashtable ht;
protected void Page_Load(object sender, EventArgs e)
{
httemp = (Session["B"] != null) ? Session["B"] as Hashtable : new Hashtable();
if (!IsPostBack)
{
Session["A"] = null;//最终
Session["B"] = null;//temp
httemp=new Hashtable();
ht = new Hashtable();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!httemp.ContainsKey(this.TextBox1.Text))
{
httemp.Add(this.TextBox1.Text, this.TextBox2.Text);
}
Session["B"] = httemp;
bandlb();
}
//ok
protected void Button2_Click(object sender, EventArgs e)
{
Session["A"] = httemp;
bandlb();
}
//cancel
protected void Button4_Click(object sender, EventArgs e)
{
httemp = (Hashtable)Session["A"];
bandlb();
}
private void bandlb()
{
this.ListBox1.DataTextField = "value";
this.ListBox1.DataValueField = "key";
this.ListBox1.DataSource = httemp;
this.ListBox1.DataBind();
}