两个ListBox的互动
来源:互联网 发布:光敏刻章软件 编辑:程序博客网 时间:2024/04/28 03:17
适合:
.Net 2.0
VS2005
效果:
ASPX页面:
CS Code :
.Net 2.0
VS2005
效果:
ASPX页面:
<table>
<tbody>
<tr>
<td>
<asp:ListBox ID="lbLeft" runat="server" SelectionMode="Multiple">
<asp:ListItem>添加名字</asp:ListItem>
<asp:ListItem>出生年月</asp:ListItem>
</asp:ListBox>
</td>
<td style="width: 27px">
<asp:Button ID="btnToRight" runat="server" Text=">>"
OnClick="btnToRight_Click" />
<br />
<asp:Button ID="btnToLeft" runat="server" Text="<<"
OnClick="btnToLeft_Click" />
</td>
<td style="width: 3px">
<asp:ListBox ID="lbRight" runat="server"
SelectionMode="Multiple"></asp:ListBox></td>
</tr>
</tbody>
</table>
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<tbody>
<tr>
<td>
<asp:ListBox ID="lbLeft" runat="server" SelectionMode="Multiple">
<asp:ListItem>添加名字</asp:ListItem>
<asp:ListItem>出生年月</asp:ListItem>
</asp:ListBox>
</td>
<td style="width: 27px">
<asp:Button ID="btnToRight" runat="server" Text=">>"
OnClick="btnToRight_Click" />
<br />
<asp:Button ID="btnToLeft" runat="server" Text="<<"
OnClick="btnToLeft_Click" />
</td>
<td style="width: 3px">
<asp:ListBox ID="lbRight" runat="server"
SelectionMode="Multiple"></asp:ListBox></td>
</tr>
</tbody>
</table>
<asp:Label ID="lblMsg" runat="server"></asp:Label>
CS Code :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Test1 : System.Web.UI.Page
{
protected void Page_Load ( object sender , EventArgs e )
{
}
protected void btnToRight_Click(object sender, EventArgs e)
{
if(lbLeft.SelectedItem != null)
{
AddItemFromSourceListBox(lbLeft, lbRight);
RemoveSelectedItem(lbLeft);
lblMsg.Text=""; //注意:为什么要这一行?
foreach(ListItem item in lbRight.Items)
{
if(item.Selected)
lblMsg.Text +=item.Text;
}
}
}
protected void btnToLeft_Click(object sender, EventArgs e)
{
if(lbRight.SelectedItem != null)
{
AddItemFromSourceListBox(lbRight, lbLeft);
RemoveSelectedItem(lbRight);
}
}
private void RemoveSelectedItem(ListBox listControl)
{
while(listControl.SelectedIndex != -1)
{
listControl.Items.RemoveAt(listControl.SelectedIndex);
}
}
private void AddItemFromSourceListBox(ListBox sourceBox,ListBox targetBox)
{
foreach(ListItem item in sourceBox.Items)
{
if(item.Selected == true && !targetBox.Items.Contains(item))
{
targetBox.Items.Add(item);
}
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Test1 : System.Web.UI.Page
{
protected void Page_Load ( object sender , EventArgs e )
{
}
protected void btnToRight_Click(object sender, EventArgs e)
{
if(lbLeft.SelectedItem != null)
{
AddItemFromSourceListBox(lbLeft, lbRight);
RemoveSelectedItem(lbLeft);
lblMsg.Text=""; //注意:为什么要这一行?
foreach(ListItem item in lbRight.Items)
{
if(item.Selected)
lblMsg.Text +=item.Text;
}
}
}
protected void btnToLeft_Click(object sender, EventArgs e)
{
if(lbRight.SelectedItem != null)
{
AddItemFromSourceListBox(lbRight, lbLeft);
RemoveSelectedItem(lbRight);
}
}
private void RemoveSelectedItem(ListBox listControl)
{
while(listControl.SelectedIndex != -1)
{
listControl.Items.RemoveAt(listControl.SelectedIndex);
}
}
private void AddItemFromSourceListBox(ListBox sourceBox,ListBox targetBox)
{
foreach(ListItem item in sourceBox.Items)
{
if(item.Selected == true && !targetBox.Items.Contains(item))
{
targetBox.Items.Add(item);
}
}
}
}
- 两个ListBox的互动
- 两个ListBox的互动方法
- 两个listBox
- VB.Net程序设计:ListBox拖动排序两个ListBox的操作
- 两个CheckBox互动
- 两个CheckBox互动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 两个listbox 复制
- 两个ListBox数据交换
- .net C# listbox的上下移动,拖动排序,两个listbox相互拖动
- [原创]两个listbox之间操作数据交换的问题!
- 两个listbox之间的互换(自定义控件)
- Winfrom 中两个listBox实现值的相互传递
- JAVA正则表达式判断图片格式
- 深入理解abstract class和interface
- 微軟下一代開發利器 - Orcas 搶先看 点击进入:Visual Studio 2008下载地址
- IC公司名录
- 基于需求的测试(RBT)
- 两个ListBox的互动
- Lex 与 Yacc 介绍(Ashish Bansal )
- 人的基本需求--自尊
- 罗素的《数理哲学导论》
- 很久没来了,没有给朋友们回复.在这给大家道歉了。
- 查看锁定表或记录得用户
- XML解析错误
- VC下使用LibTiff处理TIFF文件
- 实现网站的自动登录