I want to do multiselect without holding CTRL key. I tried this below code from StackOverFlow
<script type="text/javascript">
var selectedClientPermissions = [];
function pageLoad() {
window.alert("Test1");
var ListBox1 = document.getElementById("<%= lstLeft.ClientID %>");
for (var i = 0; i < ListBox1.length; i++) {
selectedClientPermissions[i] = ListBox1.options[i].selected;
window.alert(ListBox1.length);
}
}
function ListBoxClient_SelectionChanged(sender, args) {
var scrollPosition = sender.scrollTop;
for (var i = 0; i < sender.length; i++) {
if (sender.options[i].selected) selectedClientPermissions[i] = !selectedClientPermissions[i];
sender.options[i].selected = selectedClientPermissions[i] === true;
}
sender.scrollTop = scrollPosition;
}
This is my list box items
<div class="row" style="padding-top: 10px;">
<div class="col-lg-3">
<asp:ListBox ID="lstLeft" class="form-control" runat="server" SelectionMode="Multiple" Height="220px" onclick="ListBoxClient_SelectionChanged(this, event);">
<asp:ListItem Value="Item Lookup Code">ItemLookupCode</asp:ListItem>
<asp:ListItem Value="Qty">Qty</asp:ListItem>
<asp:ListItem Value="Total Price">Total Price</asp:ListItem>
<asp:ListItem Value="Child Item Lookup Code1">ChildItemLookupCode1</asp:ListItem>
<asp:ListItem Value="Child1Qty">Child1Qty</asp:ListItem>
<asp:ListItem Value="Total Price1">Total Price1</asp:ListItem>
<asp:ListItem Value="Child Item Lookup Code2">ChildItemLookupCode2</asp:ListItem>
<asp:ListItem Value="Child2Qty">Child2Qty</asp:ListItem>
<asp:ListItem Value="Total Price2">Total Price2</asp:ListItem>
<asp:ListItem Value="Child Item Lookup Code">ChildItemLookupCode</asp:ListItem>
<asp:ListItem Value="Child3Qty">Child3Qty</asp:ListItem>
<asp:ListItem Value="Total Price3">Total Price3</asp:ListItem>
<asp:ListItem Value="Total Quantity">Total</asp:ListItem>
<asp:ListItem Value="Extended Price">ExtendedPrice</asp:ListItem>
<asp:ListItem Value="Department Name">DepartmentName</asp:ListItem>
<asp:ListItem Value="Category Name">CategoryName</asp:ListItem>
<asp:ListItem Value="Supplier Name">SupplierName</asp:ListItem>
</asp:ListBox>
</div>
<div class="col-lg-1" style="padding-top: 70px; padding-left: 30px;">
<input type="button" id="right" value=">>"/>
<input type="button" id="left" value="<<" />
</div>
<div class="col-lg-3">
<asp:ListBox ID="FirstRight" runat="server" SelectionMode="Multiple" Width="100%" Height="220"></asp:ListBox>
<asp:HiddenField ID="HiddentxtSelectedColumn" runat="server" />
</div>
</div>
This code is working. But the problem is, after I moved the multiselected items to another list box,when i click again to select the list items, it's automatically selecting the other items which items are in the same position which was moved already.
First time select everything is correct
Second Time I select only SupplierName in the last item of listbox. But its selecting the other items which items are in the same positions of moved items.
I tried these links Multiple select listbox without pressing CTRL, How to select multiple items from a listbox asp.net without pressing the CTRL key using javascript? Nothing worked