Tuesday, 28 May 2013

ASP.Net: Move List items from one ListBox to another ListBox using Jquery

ASP.net code behind using Update panel or XMLHttpRequest is more sower than the jquery. jquery can do this real quick and with good user experience.

$(document).ready(function() {

    $('#btnRight').click(function(e) {
        var selectedOpts = $('#lstBox1 option:selected');

        if (selectedOpts.length == 0) {
            alert("Please select item (s) to move.");
            e.preventDefault();
        } 

        $('#lstBox2').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();

    });

   $('#btnLeft').click(function(e) {
        var selectedOpts = $('#lstBox2 option:selected');

        if (selectedOpts.length == 0) {
            alert("Please select item (s) to move.");
            e.preventDefault();
        }

        $('#lstBox1').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });
});​

No comments:

Post a Comment