I would like to know how I can transfer items between two ListBoxes, I want the user to double click on an item to be transferred from one listbox to another.
I did not find any events in my double-click Asp-ListBox.
In the link below you have an example of the Telerik control but it is paid, I need some solution like JavaScript
I was able to find a solution to my problem, I do not know if it is the best practice but it worked the way I needed it, java script calls the button event that does the work of changing the items without causing problems 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" />
Buttons 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();
});
});