Notes for ASP. NET 1.1 ListBox

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.