左边的ListBox里面的值添加到右边的ListBox.. 晕呼呼。不写代码了楼主想想吧。用for循环的--来remove左边的listbox的项同时加到另一个listbox里 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void JB_But1_Click(object sender, System.EventArgs e) { ListItem item=new ListItem(ViewState["name"].ToString(),ViewState["id"].ToString()); for(int i=0;i<JB_ListBox2.Items.Count ;i++) { if(JB_ListBox2.Items[i].Value==item.Value) { return ; } } this.JB_ListBox2.Items.Add(item); } ListBox1.Items.Remove(ListBox2.SelectedItem.Text);這樣嗎? ListBox1.Items.RemoveAt(ListBox1.SelectedIndex); Simple Demo:<%@ Page Language="C#" AutoEventWireup="true" %><%--http://community.csdn.net/Expert/TopicView3.asp?id=5619363--%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Button1_Click(object sender, EventArgs e) { SwapListBox(ListBox1, ListBox2); } protected void Button2_Click(object sender, EventArgs e) { SwapListBox(ListBox2, ListBox1); } private void SwapListBox(ListBox src, ListBox dst) { for (int i = 0; i < src.Items.Count; ) { ListItem item = src.Items[i]; if (item.Selected) { src.Items.Remove(item); item.Selected = dst.SelectionMode == ListSelectionMode.Multiple ? item.Selected : false; dst.Items.Add(item); continue; } i++; } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Double ListBox</title> <script type="text/javascript"> </script></head><body> <form id="form1" runat="server"> <div> <div style="float:left"> <asp:ListBox ID="ListBox1" BorderWidth="1" runat="server" SelectionMode="Multiple"> <asp:ListItem Value="Item1">Item1</asp:ListItem> <asp:ListItem Value="Item2">Item2</asp:ListItem> <asp:ListItem Value="Item3">Item3</asp:ListItem> <asp:ListItem Value="Item4">Item4</asp:ListItem> </asp:ListBox> </div> <div style="float:left;vertical-align:middle;"> <asp:Button ID="Button1" runat="server" Text=">>" OnClick="Button1_Click" /> <br /> <asp:Button ID="Button2" runat="server" Text="<<" OnClick="Button2_Click" /> </div> <div> <asp:ListBox ID="ListBox2" BorderWidth="1" runat="server"> </asp:ListBox> </div> </div> </form></body></html> private void Button1_Click(object sender, System.EventArgs e) { if(ListBox1.SelectedItem!=null) { ListBox2.Items.Add(ListBox1.SelectedValue); ListBox1.Items.Remove(ListBox1.SelectedValue); } } private void Button2_Click(object sender, System.EventArgs e) { if(ListBox2.SelectedItem!=null) { ListBox1.Items.Add(ListBox2.SelectedValue); ListBox2.Items.Remove(ListBox2.SelectedValue); } } 求 asp.net mvc 及 jquery 达人指点一下 CSDN的主界面是用框架子做来的吗? Nhibernate绑定Gridview的问题(一对多,多对一) 急问,excel导入SQL问题,刚被老板批了,请大家帮忙啊,在线等 如果输入的计划完成数和输入的实际完成数不相等,那么就必须输入原因,请问这样的验证(正则)怎么写? 关于asp.net问题 再问一个小问题! 请教一个关于程序发布的问题 WebApplication制作安装包中如何设置规定路径的目录夹? 讨论一下这个运行结果??? 困惑菜鸟的问题,请大家帮忙!(购物车问题) 客户端获取listbox当前选定的值
{
ListItem item=new ListItem(ViewState["name"].ToString(),ViewState["id"].ToString());
for(int i=0;i<JB_ListBox2.Items.Count ;i++)
{
if(JB_ListBox2.Items[i].Value==item.Value)
{
return ;
}
}
this.JB_ListBox2.Items.Add(item);
}
{
SwapListBox(ListBox1, ListBox2);
} protected void Button2_Click(object sender, EventArgs e)
{
SwapListBox(ListBox2, ListBox1);
} private void SwapListBox(ListBox src, ListBox dst)
{
for (int i = 0; i < src.Items.Count; ) {
ListItem item = src.Items[i];
if (item.Selected) {
src.Items.Remove(item);
item.Selected = dst.SelectionMode == ListSelectionMode.Multiple ? item.Selected : false;
dst.Items.Add(item);
continue;
}
i++;
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Double ListBox</title>
<script type="text/javascript">
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div style="float:left">
<asp:ListBox ID="ListBox1" BorderWidth="1" runat="server" SelectionMode="Multiple">
<asp:ListItem Value="Item1">Item1</asp:ListItem>
<asp:ListItem Value="Item2">Item2</asp:ListItem>
<asp:ListItem Value="Item3">Item3</asp:ListItem>
<asp:ListItem Value="Item4">Item4</asp:ListItem>
</asp:ListBox>
</div>
<div style="float:left;vertical-align:middle;">
<asp:Button ID="Button1" runat="server" Text=">>" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Text="<<" OnClick="Button2_Click" />
</div>
<div>
<asp:ListBox ID="ListBox2" BorderWidth="1" runat="server">
</asp:ListBox>
</div>
</div>
</form>
</body>
</html>
{
if(ListBox1.SelectedItem!=null)
{
ListBox2.Items.Add(ListBox1.SelectedValue);
ListBox1.Items.Remove(ListBox1.SelectedValue);
}
} private void Button2_Click(object sender, System.EventArgs e)
{
if(ListBox2.SelectedItem!=null)
{
ListBox1.Items.Add(ListBox2.SelectedValue);
ListBox2.Items.Remove(ListBox2.SelectedValue);
}
}