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);
}
}
}
}
查看全文
相关阅读:
Python 使用 environs 库来更好地定义环境变量
五分钟带你了解map、reduce和filter
部署React前端和Django后端的3种方法
marshmallow库更优雅的数据转换
利用 attrs 和 cattrs 两个库实现 Python 面向对象编程
parse库,更友好的格式化数据提取方案
python之prettytable模块格式化打印
使用类型注解让 Python 代码更易读
jksj算法训练营-第三课01 数组、链表、跳表
linux安装java步骤
原文地址:https://www.cnblogs.com/sinkzephyr/p/862632.html
最新文章
【vscode 报错】Couldn't start client ESLint
vscode底部状态栏不见了
下载了query-string包导致webpack打包失败
http缓存机制实践
前端生成唯一uuid
http请求常见的状态码
axios设置请求头失效的问题
前端Cannot read property 'disabled' of null 问题解决
git命令
解决报错(Navigation cancelled from “/roleList“ to “/userlist“ with a new navigation.)
热门文章
Git小乌龟的安装及使用
码云如何创建属于自己的仓库 及 使用Git 命令行上传自己的项目代码至码云
本地项目代码上传到远端GitLab仓库
Echarts根据数据变换柱状图柱状的颜色
vant-tab 修改样式
关于ECharts仪表盘的全部相关配置
Vue:将px转化为rem,适配移动端
vue----js-cookie的使用方法
VUE中页面F5刷新空白并报错报错:Uncaught SyntaxError: Unexpected token <解决方法
Python知识点汇总
Copyright © 2011-2022 走看看