Listbox multi-choice for moving up and down js edition and Server Edition

Source: Internet
Author: User

<% @ 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 ;}}

 

 

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.