效果:
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/26215837843.jpg)
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
>
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;
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
public
partial
class
Test1 : System.Web.UI.Page
{
protected void Page_Load ( object sender , EventArgs e )
{
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
}
protected void btnToRight_Click(object sender, EventArgs e)
{
if(lbLeft.SelectedItem != null)
{
AddItemFromSourceListBox(lbLeft, lbRight);
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
RemoveSelectedItem(lbLeft);
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
lblMsg.Text=""; //注意:为什么要这一行?
foreach(ListItem item in lbRight.Items)
{
if(item.Selected)
lblMsg.Text +=item.Text;
}
}
}
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
protected void btnToLeft_Click(object sender, EventArgs e)
{
if(lbRight.SelectedItem != null)
{
AddItemFromSourceListBox(lbRight, lbLeft);
RemoveSelectedItem(lbRight);
}
}
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
private void RemoveSelectedItem(ListBox listControl)
{
while(listControl.SelectedIndex != -1)
{
listControl.Items.RemoveAt(listControl.SelectedIndex);
}
}
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
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);
}
}
}
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
}
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/26215837843.jpg)
ASPX页面:
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
OnClick = " btnToRight_Click " />
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
OnClick = " btnToLeft_Click " />
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
SelectionMode = " Multiple " ></ asp:ListBox ></ td >
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
CS Code :
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/None.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockStart.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedSubBlockEnd.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/InBlock.gif)
![](http://www.zxbc.cn/Files/BeyondPic/2007-7/27/ExpandedBlockEnd.gif)