The theme of the day is about C # basics, vs controls, and ado.net. Among the three, the controls in vs are described in great detail.
The following describes how to use The ListBox control.
The controls used in this example include labels, ListBox, and buttons.
As follows:
Set the selectionmode attribute of the list box to multiple to select multiple items.
The Code is as follows:
Protected void page_load (Object sender, eventargs e) {label2.text = "sort the following heroes to your liking:"; label2.font. bold = true; label2.font. size = 16;} protected void btnup_click (Object sender, eventargs e) {// move an IF (button) sender) up or down ). commandname = "up" & lsbshow. selectedindex> 0 | (button) sender ). commandname = "down" & lsbshow. selectedindex <lsbshow. items. count-1) {// determine whether the sent command must be up and the index of the selected entry must be greater than 0, or down, and the selected entry must rain down the int index; // to reduce the code, here we will make a judgment on the variable, and then directly call the variable if (button) sender ). commandname = "up") {Index =-1; // The subsequent index will be added to or subtracted from the current index} else {Index = 1 ;} listitem lT = new listitem (lsbshow. selecteditem. text, lsbshow. selectedvalue); lsbshow. items [lsbshow. selectedindex]. TEXT = lsbshow. items [lsbshow. selectedindex + Index]. text; lsbshow. items [lsbshow. selectedindex]. value = lsbshow. items [lsbshow. selectedindex + Index]. value; lsbshow. items [lsbshow. selectedindex + Index]. TEXT = lt. text; lsbshow. items [lsbshow. selectedindex + Index]. value = lt. value; lsbshow. selectedindex = lsbshow. selectedindex + index;} protected void btnfirst_click (Object sender, eventargs e) {// to the first lsbshow. selectedindex = 0;} protected void btnlast_click (Object sender, eventargs e) {// to the last lsbshow. selectedindex = lsbshow. items. count-1;} protected void btnbefore_click (Object sender, eventargs e) {// The Last lsbshow. selectedindex = lsbshow. selectedindex-1;} protected void btnnext_click (Object sender, eventargs e) {// next lsbshow. selectedindex = lsbshow. selectedindex + 1 ;}
The "btnup_click" event is returned when the move up and move down button is clicked. The corresponding code is as follows:
<P> <asp: button id = "btnup" runat = "server" text = "Move Up" commandname = "up" onclick = "btnup_click"/> <asp: button id = "btndown" runat = "server" text = "Move Down" commandname = "down" onclick = "btnup_click"/> </P>
The effect is as follows: