jquery move and sort the implementation code

Source: Internet
Author: User


public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
if (!ispostback)
{
Binddata ();
}
}
private void Binddata ()
{
ArrayList List=dataarray ();
for (int i = 0; i < List.count; i++)
{
Listall.items.add (List[i].tostring ());
listall.items[i].attributes["tag"] = i.ToString (); Sort fields with Tag records
}
}
Private ArrayList DataArray ()
{
Some of the data used, this is the default by the first word phonetic sorting
ArrayList list = new ArrayList ();
List.add ("Strawberry");
List.add ("pear");
List.add ("Orange");
List.add ("Mango");
List.add ("Apple");
List.add ("banana");
return list;
}
}

Code


<table border= "0" >
<tr>
<TD width= "156" > All Fruits:</td>
<TD width= > </td>
<TD width= "482" > My chosen:</td>
</tr>
<tr>
<TD rowspan= "2" ><asp Tutorial: ListBox selectionmode= "multiple" id= "Listall" rows= "" width= "156" runat= "Server" ></asp:listbox></td>
<TD height= "A" align= "center" >
<input type= "button" id= "Btnleftmove" value= ">>>" onclick= "Move (' Listall ', ' listmy ');" /><br/><br/>
<input type= "button" id= "Btnrighttmove" value= "<<<" onclick= "Move (' listmy ', ' Listall ');" />
</td>
<TD rowspan= "2" ><asp:listbox selectionmode= "multiple" id= "Listmy" rows= "" width= "156" runat= "Server" > </asp:listbox></td>
</tr>
</table>


Jquery


Mobile User-selected roles
SetName: List name to move out of data getname: List name to move data into
function Move (setname,getname)
{
var size=$ ("#" +setname+ "option"). Size ();
var selsize=$ ("#" +setname+ "option:selected"). Size ();
if (size>0&&selsize>0)
{
$.each ($ ("#" +setname+ "option:selected"), function (Id,own) {
var text=$ (Own). text ();
var tag=$ (Own). attr ("tag");
$ ("#" +getname). Prepend ("<option tag=" "+tag+" ">" +text+ "</option>");
$ (Own). Remove ();
$ ("#" +setname+ ""). Children ("Option:first"). attr ("selected", true);
});
}
Reorder
$.each ($ ("#" +getname+ "option"), function (Id,own) {
Orderrole (GetName);
});
}
Sort role list by first letter
function Orderrole (listname)
{
var size=$ ("#" +listname+ "option"). Size ();
var one=$ ("#" +listname+ "Option:first-child");
if (size>0)
{
var text=$ (one). text ();
var tag=parseint ($ (one). attr ("tag"));
All elements under the first value in the Loop list
$.each ($ (one). Nextall (), function (Id,own) {
var nextag=parseint ($ (own). attr ("tag");
if (Tag>nextag)
{
$ (one). Remove ();
$ (Own). After ("<option tag=" "+tag+" ">" +text+ "</option>");
One=$ (Own). Next ();
}
});
}
}

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.