zoukankan
html css js c++ java
两个ListBox的互动
适合:
.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
=
"
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
=
"
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);
}
}
}
}
查看全文
相关阅读:
ISC DHCP: Enterprise grade solution for configuration needs
The most widely used name server software: BIND
不是技术牛人,如何拿到国内IT巨头的Offer--转
NVIDIA---CUDA
BIOS
Computer form factor
OC-常见错误 方法与函数的区别
OC-面向对象
OC-基本
C-结构体、枚举
原文地址:https://www.cnblogs.com/sinkzephyr/p/862632.html
最新文章
uiautomator2 +Python进行Android原生应用UI测试
使用moneykey对APP进行健壮性测试
【转】requests、BeautifulSoup使用总结
python 爬虫知识点
【转】Celery 分布式任务队列快速入门
python redis使用方法
使用threadpool并发测试,报错HTTPConnectionPool Max retires exceeded
my live / clothes size
java jvm optimization / -Xms -Xmx -Xmn -Xss
java http tools / postman / postwoman /
热门文章
my read / zikao / jiangsushengjiaoyukaoshiyuan
springBoot使用feign实现远程接口调用和错误熔断
java8特性--list集合根据多个字段去重
docker安装jenkins最新版本
springBoot整合redis--让缓存成为你系统的一部分
Angular使用 ElementRef + Renderer2 全局设置组件属性
Network Booting
UUID GUID
Serial attached SCSI
服务器----1U、2U、3U、4U
Copyright © 2011-2022 走看看