In ASP. net1.1, to transfer data between two listboxes, for example, two ListBox listbox1 and listbox2
<Asp: ListBox id = "listbox1" style = "Z-INDEX: 101; left: 56px; position: absolute; top: 72px" runat = "server" Height = "150px"
Width = "100px">
<Asp: listitem value = "single-chip microcomputer"> Single-Chip Microcomputer </ASP: listitem>
<Asp: listitem value = "NetworkProgramDesign "> Network Program Design </ASP: listitem>
<Asp: listitem value = "e-commerce"> E-Commerce </ASP: listitem>
<Asp: listitem value = "computer graphics"> Computer Graphics </ASP: listitem>
<Asp: listitem value = "Distributed System"> Distributed System </ASP: listitem>
<Asp: listitem value = "JSP technology"> JSP technology </ASP: listitem>
</ASP: ListBox>
<Asp: ListBox id = "listbox2" style = "Z-INDEX: 102; left: 240px; position: absolute; top: 72px" runat = "server" Height = "150px"
Width = "100px"> </ASP: ListBox>
Add two buttons button1 and button2
<Asp: button id = "button1" style = "Z-INDEX: 103; left: 168px; position: absolute; top: 96px "runat =" server "width =" 60px "text ="
Add "> </ASP: button>
<Asp: button id = "button2" style = "Z-INDEX: 104; left: 168px; position: absolute; top: 152px "runat =" server "width =" 60px "text ="
Delete "> </ASP: button>
Add a click event to button1
Private void button#click (Object sender, system. eventargs E)
{
This. listbox2.items. Add (this. listbox1.selecteditem );
This. listbox1.items. Remove (this. listbox1.selecteditem );
}
Click Event of button2
Private void button2_click (Object sender, system. eventargs E)
{
This. listbox1.items. Add (this. listbox2.selecteditem );
This. listbox2.items. Remove (this. listbox2.selecteditem );
}
Hypothetical: On the surface, the basic functions have been implemented. Compile and run the program. Click "add" and choose "listbox1" to go to listbox2. Click "error" again. "When selectionmode is single, listBox cannot have multiple selected items."
Correction Method 1: Modify the selectionmode attribute of listbox1 and listbox2 to multiple, which can be basically achieved, but the effect is very low.
Method 2: do not modify the selectionmode attribute of listbox1 and listbox2.Code
Private void button#click (Object sender, system. eventargs E)
{
This. listbox2.items. Add (this. listbox1.selecteditem );
This. listbox2.selectedindex = 0;
This. listbox1.items. Remove (this. listbox1.selecteditem );
}
Hypothetical re-emergence: When you click Add for the first time, the selected items in listbox1 are added to listbox2, and selected items in listbox1 are deleted. Click again, and the items in listbox1 are
Added to listbox2 again, but selected items in listbox1 are removed. I suspect it is the impact of selectindex, IN THE NEXT modification code
Private void button#click (Object sender, system. eventargs E)
{
This. listbox2.items. Add (this. listbox1.selecteditem );
This. listbox1.items. Remove (this. listbox1.selecteditem );
This. listbox2.selectedindex = 0;
}
In this way, you can