<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "X200906021128.aspx. cs" Inherits = "ListBoxs_X200906021128" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head runat =" server "> <title> </title> <script type =" text/javascript "> function MoveUP (fElement) {if (fElement. options. length = 0 | fElement. options [0]. selected) return; for (var I = 1; I <fElement. options. length; I ++) {if (fElement. options [I]. selected) {var text = fElement. options [I]. text; var value = fElement. options [I]. value; var selected = fElement. options [I]. selected; fElement. options [I]. text = fElement. options [I-1]. text; fElement. options [I]. value = fElement. options [I-1]. value; fElement. options [I]. selected = fElement. options [I-1]. selected; fElement. options [I-1]. text = text; fElement. options [I-1]. value = value; fElement. options [I-1]. selected = selected ;}} function MoveDown (fElement) {if (fElement. options. length = 0 | fElement. options [fElement. options. length-1]. selected) return; for (var I = fElement. options. length-1; I>-1; I --) {if (fElement. options [I]. selected) {var text = fElement. options [I + 1]. text; var value = fElement. options [I + 1]. value; var selected = fElement. options [I + 1]. selected; fElement. options [I + 1]. text = fElement. options [I]. text; fElement. options [I + 1]. value = fElement. options [I]. value; fElement. options [I + 1]. selected = fElement. options [I]. selected; fElement. options [I]. text = text; fElement. options [I]. value = value; fElement. options [I]. selected = selected ;}}</script>
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; public partial class ListBoxs_X200906021128: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {for (int I = 0; I <20; I ++) fListBox. items. add (I. toString () ;}} protected void btnUp_Click (object sender, EventArgs e) {// No items, or if (this. fListBox. items. count = 0 | this. fListBox. items [0]. selected) return; for (int I = 1; I <this. fListBox. items. count; I ++) {if (this. fListBox. items [I]. selected) this. changeProperty (this. fListBox. items [I-1], this. fListBox. items [I]) ;}} protected void btnDown_Click (object sender, EventArgs e) {// No, or the last selected node is already the first, if (this. fListBox. items. count = 0 | this. fListBox. items [this. fListBox. items. count-1]. selected) return; for (int I = this. fListBox. items. count-1; I>-1; I --) {if (this. fListBox. items [I]. selected) this. changeProperty (this. fListBox. items [I], this. fListBox. items [I + 1]) ;}} private void ChangeProperty (ListItem fFront, ListItem fCurrent) {string fText = fFront. text; string fValue = fFront. value; bool fSelected = fFront. selected; fFront. text = fCurrent. text; fFront. value = fCurrent. value; fFront. selected = fCurrent. selected; fCurrent. text = fText; fCurrent. value = fValue; fCurrent. selected = fSelected ;}}