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);
}
}
}
}
查看全文
相关阅读:
于丹关于人性的总结
Oracle中的MS SQLSERVER@@ERROR
分享2011年10月网上随机搜集的超酷超有趣的web开发和Javascript代码
来自Nike Better World的视差滚动(Parallax Scrolling)特效 分享一些教程和灵感
2011年最新使用CSS3实现各种独特悬浮效果的教程
分享2011年50个最棒的wordpress主题 第一部分
分享2011年50个最棒的wordpress主题
分享一个超酷创建互动文档的Javascript类库 tangle
jQuery Howto: 如何快速创建一个AJAX的"加载"的图片效果
什么时候我们该选择VPS服务器?
原文地址:https://www.cnblogs.com/sinkzephyr/p/862632.html
最新文章
.net(c#)数学计算资料(持续更新)
msdtc服务
毕业论文
C# ToString()方法
C# override
C# string 与 String
WPF的控件ToolTip
C# params
修改引用的值 与 修改引用
C# int 与 string的相互转型
热门文章
C# 值类型 VS 引用类型
C# ref,out
修改引用的值 与 修改引用(通过方法)
ORA02070: database SALES does not support operator USERENV in this context
New Year Message of information departments
利用DB Link实现数据库间的表同步
数据同步概述
转换表结构例子
OM 订单状态
ORACLE SQL性能优化三
Copyright © 2011-2022 走看看