We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Dual LIstBox , first Box empty, move items from Second Box

Hi

Have managed to create 2 list boxes with second list box populated with items . Want to move selected items from Second list box to first list box . How do I achieve this?

( first list box is empty. Second listbox has items.  The items when moved to first list box do not appear)

Secondly the list box are part of a form, therefore on submit how do I retrieve the selected items?


Thank you
Sanjay

5 Replies

VK Vinoth Kumar Sundara Moorthy Syncfusion Team July 9, 2019 09:30 AM UTC

Hi Sanjay, 
 
Good day to you. 
 
Query-1:  first list box is empty. Second listbox has items.  The items when moved to first list box do not appear 
 
We have checked your reported issue and it is known issue. We have already created the defect report for this and you can track the status this report using below link from feedback portal, 
 
 
We will include this fix in our upcoming Essential Studio 2019 Volume 2 release, which will be available in the mid of this month. Meanwhile we would like to suggest workaround solution using created event in ListBox as like in the below code example,   
 
Code Example 
<div class="control-section"> 
    <div class="dual-list-wrapper"> 
        <div class="dual-list-groupa"> 
            <h4>Group A</h4> 
            <form method="post" asp-action="ProcessForm"> 
                <ejs-listbox id="listbox1" scope="#listbox2" name="listbox1" dataSource="ViewBag.groupA" created="onCreate"> 
                    <e-listbox-fields text="Name"></e-listbox-fields> 
                    <e-listbox-toolbarSettings items="ViewBag.items"> 
                    </e-listbox-toolbarSettings> 
                </ejs-listbox> 
        </div> 
        <div class="dual-list-groupb"> 
            <h4>Group B</h4> 
            <ejs-listbox id="listbox2" name="listbox2" dataSource="ViewBag.groupB" created="onCreate"> 
                <e-listbox-fields text="Name"></e-listbox-fields> 
            </ejs-listbox> 
        </div> 
        </form> 
    </div> 
</div> 
<script> 
    function onCreate() { 
        var toolbarBtn = document.querySelectorAll(".e-listbox-tool")[0].children; 
        for (var i = 0, len = toolbarBtn.length; i < len; i++) { 
            toolbarBtn[i].type = "button"; 
        } 
    } 
</script 
 
Query-2: how do I retrieve the selected items? 
We have checked your requirement and it can be achieved by using name property in form post action. 
In the below code example, you can get the ListBox selected items while clicking the submit button.  
  
 
 
 
Could you please check the above sample and get back to us for further assistance on this? 
 
Regards, 
Vinoth Kumar S 



SA Sanjay July 10, 2019 09:43 AM UTC

Hi Vinoth

The sample works on its own . But once I combine the code with my project it does not work. I am using version 17.1.0.53, ASP.NET Core 2.2

Thanks
Sanjay


VK Vinoth Kumar Sundara Moorthy Syncfusion Team July 11, 2019 11:37 AM UTC

Hi Sanjay, 
 
Thank you for the update. 
 
Query: Your sample works on its own. But once I combine the code with my project it does not work 
 
We would like to know the following details to proceed further, 
 
1.       Share your complete code snippet. 
2.       Check and share the stack trace / console window, if you got any errors 
 
Could you please get back to us with above requested information? Based on that we will validate and provide you better solution quickly.  
 
Regards, 
Vinoth Kumar S 



SA Sanjay August 2, 2019 03:56 AM UTC

Hi

Thank you. It is working. Mistake was on my end. There was a mistake in my code.  Now have another question.

I can move items between boxes. On submit only selected items are posted back to the server. If no items are selected , then nothing is posted. Is there a way to send back all items in box A to the server on submit?

Thanks again
Sanjay
 


VK Vinoth Kumar Sundara Moorthy Syncfusion Team August 2, 2019 01:35 PM UTC

Hi Sanjay, 
 
Thank you for the update. 
 
We have checked your requirement and it can be achieved by using selectAll method in ListBox component. In the below code example, all the items in ListBox A posted back to server on submit button click, by using selectAll method. 
  
Code Example 
<button id="submitButton" class="e-btn" onclick="btnClick()">Submit</button> 
 
<script> 
    function btnClick() { 
        var listboxObj = document.getElementById("listbox1").ej2_instances[0]; 
        if (listboxObj.value.length == 0) 
            listboxObj.selectAll(); 
    } 
</script> 
 
For your convenience, we have prepared a sample and the same can be downloaded from the below link, 
 
Could you please check the above details and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon