How to transfer items between Listbox with Double Click

Asked

Viewed 242 times

2

I would like to know how I can transfer items between two Listbox, I want that when the user of two clicks on an item the same is already transferred from one listbox to the other.

I did not find any event in my Asp-Listbox double click.

In the link below there is an example of Telerik control but it is paid, I need some solution as Javascript

http://demos.telerik.com/aspnet-ajax/listbox/examples/functionality/transfer/defaultcs.aspx

I managed to find a solution to my problem, I do not know if it is the best practice but it worked the way I needed, The java script calls the event button that does the job of changing the items without causing problem at the time of recording.

Button Code

<asp:ImageButton ID="imgbDireita" ImageUrl="~/Imagens/Icones/SetaDireita.png"  runat="server" OnClick="imgbDireita_Click" />
<asp:ImageButton ID="imgbEsquerda" ImageUrl="~/Imagens/Icones/SetaEsquerda.png" runat="server" OnClick="imgbEsquerda_Click" />

Button Event

protected void imgbDireita_Click(object sender, ImageClickEventArgs e)
    {
        if (lstCompartimentosAtivos.SelectedIndex >= 0)
        {
            lstCompartimentosInativos.Items.Add(lstCompartimentosAtivos.Items[lstCompartimentosAtivos.SelectedIndex]);
            lstCompartimentosAtivos.Items.RemoveAt(lstCompartimentosAtivos.SelectedIndex);
            lstCompartimentosInativos.SelectedIndex = -1;
            lstCompartimentosAtivos.SelectedIndex = -1;
        }
    }

 protected void imgbEsquerda_Click(object sender, ImageClickEventArgs e)
    {
        if (lstCompartimentosInativos.SelectedIndex >= 0)
        {
            lstCompartimentosAtivos.Items.Add(lstCompartimentosInativos.Items[lstCompartimentosInativos.SelectedIndex]);
            lstCompartimentosInativos.Items.RemoveAt(lstCompartimentosInativos.SelectedIndex);
            lstCompartimentosInativos.SelectedIndex = -1;
            lstCompartimentosAtivos.SelectedIndex = -1;
        }
    }

Java Script

jQuery(document).ready(function () {

function ativoParaInativo() {
    var imgb = document.getElementById('<%=imgbDireita.ClientID%>');
          imgb.click();
}

function inativoParaAtivo() {
      var imgb = document.getElementById('<%=imgbEsquerda.ClientID%>');
            imgb.click();
}

        $('#cphConteudo_tabImovel_tabCompartimentos_lstCompartimentosAtivos').dblclick(function () {
            ativoParaInativo();
        });

        $('#cphConteudo_tabImovel_tabCompartimentos_lstCompartimentosInativos').dblclick(function () {
            inativoParaAtivo();
        });

});
  • Look if here can help you. https://api.jquery.com/dblclick/

1 answer

2

  • I did the test and the display part works but at the time of recording when I go through the listbox in code Behind it does not catch the changes. I put the code above.

  • As you are using the component Asp, in Submit I can’t tell you. But I would solve, for example, saving by ajax. You can take your #cphConteudo_tabImovel_tabCompartitions This way you will have the ids of tb active and can send an array. (=

  • Can you show me an example of code for how to do this?

  • Something like this: var lAtivos = new Array(); $("#cphConteudo_tabImovel_tabCompartitions each(Function () { lAtivos.push($(this).attr("id"); }); $. post("page.aspx", { action: "save", listIDs: lAtivos }, Function (return) { }); . (=

  • Managed to solve otherwise, I will put the code on top. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.