日期:2014-05-18 浏览次数:20578 次
while (ListBox1.SelectedIndex > -1)
{
if (ListBox1.SelectedItem.Selected)
{
ListBox2.Items.Add(ListBox1.SelectedItem);
}
ListBox1.Items.Remove(ListBox1.SelectedItem);
}
foreach 判断每个选择项是否被选上
------解决方案--------------------
可以的啊
例子
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
ListBox2.Items.Clear();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
ListBox2.Items.Add(ListBox1.Items[i].Value);
}
}
}
void BindTextBox1()
{
//模拟下
ListBox1.Items.Add("A");
ListBox1.Items.Add("B");
ListBox1.Items.Add("C");
ListBox1.Items.Add("D");
ListBox1.Items.Add("E");
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindTextBox1();
}
}
</script>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server" SelectionMo