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 ();
}
});
}
}