Choose between two ListBox options

Source: Internet
Author: User

1. Double-click the ListBox option on the left to add it to the ListBox on the right. After testing, it has been successfully added.

Protected void page_load (Object sender, eventargs e) <br/>{< br/> If (! Ispostback) <br/>{</P> <p> If (! Page. isstartupscriptregistered ("lstcarleft") {listbox_dblclick ("lstcarleft", page, lstcarleft, "lstcarleft", "lstcarright") ;}< br/> If (! Page. isstartupscriptregistered ("lstcarright") {listbox_dblclick ("lstcarright", page, lstcarright, "lstcarright", "lstcarleft ");} <br/>}</P> <p> Public void listbox_dblclick (string key, page, system. web. UI. webcontrols. webcontrol, string removelistbox, string addlistbox) <br/>{< br/> removelistbox = "document. getelementbyid ('"+ removelistbox +"') "; addlistbox =" en T. getelementbyid ('"+ addlistbox +"') "; <br/> string mflistboxjs =" <MCE: script language = JavaScript> <! -- <Br/> Function Change (removelistbox, addlistbox) "; <br/> mflistboxjs ++ =" {"; <br/> mflistboxjs + =" Var addoption = document. createelement ('option');/N "; <br/> mflistboxjs + =" Var index1;/N "; mflistboxjs + =" If (removelistbox. length = 0) Return (false);/N "; <br/> mflistboxjs + =" index1 = removelistbox. selectedindex;/N "; mflistboxjs + =" If (index1 <0) Return (false);/N "; <br/> mflistboxjs + =" addoption. TEXT = removelistbox. options (index1 ). text;/N "; <br/> mflistboxjs + =" addoption. value = removelistbox. value;/N "; <br/> mflistboxjs + =" addlistbox. add (addoption);/N "; <br/> mflistboxjs ++ =" removelistbox. remove (index1)/n "; <br/> mflistboxjs ++ ="} "; <br/> mflistboxjs ++ =" <br/> // --> </MCE: SCRIPT> "; <br/> page. registerstartupscript (Key, mflistboxjs); <br/> webcontrol. attributes. add ("ondblclick", "Change (" + removelistbox + "," + addlistbox + ");"); <br/>}< br/>

 

 

2. Put two left and right arrows in the two listboxes. Click add or delete. The following method is better, and you can count the data in the ListBox when the left and right are moved.

The following statistics increase the amount in ListBox ..

Protected void imgbtnadd_click (Object sender, imageclickeventargs e) <br/>{< br/> decimal sum = convert. todecimal (viewstate ["sum"]); </P> <p> If (lstcarleft. selecteditem = NULL) <br/>{< br/> scriptmanager. registerstartupscript (this, GetType (), "84", "alert ('select the license plate number on the Left ');", true); </P> <p> return; <br/>}< br/> for (INT I = 0; I <lstcarleft. items. count; I ++) <br/>{< br/> If (lstcarleft. items [I]. selected) <br/>{< br/> listitem li = new listitem (); <br/> Li. TEXT = lstcarleft. selecteditem. text; <br/> Li. value = lstcarleft. selectedvalue; <br/> string [] strvalue = spit (Li. value, "*"); <br/> sum + = int. parse (strvalue [1]); </P> <p> lstcarright. items. add (LI); </P> <p> lstcarleft. items. remove (lstcarleft. selecteditem); <br/>}</P> <p> viewstate ["sum"] = sum; <br/>}< br/> txt_jsje.text = viewstate ["sum"]. tostring (); <br/> txt_ysje.text = viewstate ["sum"]. tostring (); </P> <p >}</P> <p> // <summary> <br/> // remove the ListBox on the right <br/> // </Summary> <br/> /// <Param name = "sender"> </param> <br/> /// <Param name = "E"> </Param> <br/> protected void imgbtnremove_click (Object sender, imageclickeventargs e) <br/>{</P> <p> decimal sum = convert. todecimal (viewstate ["sum"]); <br/> If (lstcarright. selecteditem = NULL) <br/>{< br/> scriptmanager. registerstartupscript (this, GetType (), "84", "alert ('select the license plate number on the right');", true); </P> <p> return; <br/>}< br/> for (INT I = 0; I <lstcarright. items. count; I ++) <br/>{</P> <p> If (lstcarright. items [I]. selected) <br/>{< br/> listitem li = new listitem (); <br/> Li. TEXT = lstcarright. selecteditem. text; <br/> Li. value = lstcarright. selectedvalue; <br/> lstcarleft. items. add (LI); <br/> string [] strvalue = spit (Li. value, "*"); </P> <p> sum-= convert. todecimal (strvalue [1]); <br/> lstcarright. items. remove (lstcarright. selecteditem); <br/>}< br/> viewstate ["sum"] = sum; <br/>}< br/> txt_jsje.text = viewstate ["sum"]. tostring (); <br/> txt_ysje.text = viewstate ["sum"]. tostring (); <br/>}

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.