Directly copy the code and run it directly:
ASPX code
<% @ Page Language = "C #" EnableEventValidation = "false" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script runat = "server">
Protected void button#click (object sender, EventArgs e)
{
Response. Write ("<li> s1 =" + Request. Form [s1.UniqueID]);
Response. Write ("<li> s2 =" + Request. Form [s2.UniqueID]);
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Script type = "text/javascript">
Var bak = null;
Function setData (){
Ss1 = document. getElementById ("<% = s1.ClientID %> ");
Ss2 = document. getElementById ("<% = s2.ClientID %> ");
If (bak = null ){
Bak = [];
For (I = 0; I <ss1.length; I ++) bak. push (ss1 [I]. value );
}
For (I = ss1.length-1; I>-1; I --){
If (ss1 [I]. selected ){
Ss2.options [ss2.options. length] = new Option (ss1 [I]. value, ss1 [I]. value );
Ss1 [I]. parentNode. removeChild (ss1 [I]);
}
}
SortSelect (ss1 );
SortSelect (ss2 );
}
Function removeData (){
Ss1 = document. getElementById ("<% = s1.ClientID %> ");
Ss2 = document. getElementById ("<% = s2.ClientID %> ");
For (I = ss2.length-1; I>-1; I --){
If (ss2 [I]. selected ){
Ss1.options [ss1.options. length] = new Option (ss2 [I]. value, ss2 [I]. value );
Ss2 [I]. parentNode. removeChild (ss2 [I]);
}
}
SortSelect (ss1 );
SortSelect (ss2 );
}
Function SortSelect (ss ){
Var tt = [];
For (I = 0; I <bak. length; I ++ ){
For (j = 0; j <ss. length; j ++ ){
If (ss [j]. value = bak [I]) tt. push (bak [I]);
}
}
Ss. length = 0;
For (I = 0; I <tt. length; I ++ ){
Ss. options [ss. options. length] = new Option (tt [I], tt [I]);
}
}
</Script>
</Head>
<Body>
<Form runat = "server" id = "form1">
<Table>
<Tr>
<Td>
<Asp: ListBox ID = "s1" runat = "server" SelectionMode = "Multiple" Rows = "6">
<Asp: ListItem> A </asp: ListItem>
<Asp: ListItem> B </asp: ListItem>
<Asp: ListItem> C </asp: ListItem>
<Asp: ListItem> D </asp: ListItem>
</Asp: ListBox>
</Td>
<Td>
<Input onclick = "setData ()" type = "button" value = "->"/>
<Br/>
<Input onclick = "removeData ()" type = "button" value = "<-"/>
</Td>
<Td>
<Asp: ListBox ID = "s2" runat = "server" SelectionMode = "Multiple" Rows = "6"> </asp: ListBox>
</Td>
</Tr>
</Table>
<Asp: Button ID = "Button1" runat = "server" onclick = "button#click" Text = "get selected"/>
</Form>
</Body>
</Html>