Asp.Net 2つのListBox間のオプション転送(ブラウザ側実装)

2711 ワード





    function MoveItem(ctrlSource, ctrlTarget) {
        var Source = document.getElementById(ctrlSource);
        var Target = document.getElementById(ctrlTarget);

        if ((Source != null) && (Target != null)) {
            while ( Source.options.selectedIndex >= 0 ) {
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[Source.options.selectedIndex].text;
                newOption.value = Source.options[Source.options.selectedIndex].value;
                
                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(Source.options.selectedIndex);  //Remove the item from Source
            }
        }
    }




    



    <form id="form1" runat="server">
  <table>               
    <tr>
        <td>
            <listbox id="ListBox1" runat="server" width="150px" height="150px" selectionmode="Multiple">
                <listitem value="1">One</listitem>
                <listitem value="2">Two</listitem>
                <listitem value="3">Three</listitem>
            </listbox>
        </td>
        <td>
            <p>
                <input onclick="Javascript:MoveItem('ListBox1', 'ListBox2');" type="button" value="->"/>
            </p>
            <p>
                <input onclick="Javascript:MoveItem('ListBox2', 'ListBox1');" type="button" value="<-"/>
            </p>
        </td>
        <td>
            <listbox id="ListBox2" runat="server" width="150px" height="150px" selectionmode="Multiple">
                <listitem value="8">Eight</listitem>
                <listitem value="9">Nine</listitem>
                <listitem value="10">Ten</listitem>
            </listbox>
        </td>
    </tr>                  
</table>
        <div>
        </div>
    </form>


</code></pre> 
 <p>    :<br/> https://social.msdn.microsoft.com/Forums/sqlserver/ja-JP/93c0b3b1-6f91-4487-aa62-c32db0e9e0a4?forum=aspnetja</p> 
</article>
                            </div>
                        </div>