分类:
2008-10-15 13:46:24
在ASP1.1中如果要实现两个ListBox相互传递数据,比如有两个ListBox ListBox1 和 ListBox2 Width="100px"> Width="100px">
添加两个Button button1 和 button2
给button1添加Click事件
private void Button1_Click(object sender, System.EventArgs e)
{
this.ListBox2.Items.Add(this.ListBox1.SelectedItem);
this.ListBox1.Items.Remove(this.ListBox1.SelectedItem);
}
button2的Click事件
private void Button2_Click(object sender, System.EventArgs e)
{
this.ListBox1.Items.Add(this.ListBox2.SelectedItem);
this.ListBox2.Items.Remove(this.ListBox2.SelectedItem);
}
假象 :表面上看基本的功能已经实现了,编译运行,点击"添加"按钮ListBox1中选中的确实跑到ListBox2中了,再次点击 出现错误“当SelectionMode 为 Single 时,ListBox 不能有多个选定项。”
改正方法1:修改ListBox1 和 ListBox2的SelectionMode 属性 设置为 Multiple ,基本上可以实现,但是效果很次。
[1]