Retrieve element from listbox

Hello

i'm working with Dual ListBox and I cannot get the data from the 2nd list to save them in the DB

Here is an example of what I do


I tried to used what is demonstrated here https://www.syncfusion.com/forums/157457/how-to-get-all-selected-items-in-a-list-box with no luck


The code is here

Available

DataSource="@projectListSource" Scope="scope2"

TItem="Project" @attributes="listbox1Attr">

Added to current campaign

DataSource="@projectListTarget"

TItem="Project"

@bind-Value="@projects"

@attributes="listbox2Attr">


When I use the bind-Value nothing is inserted in @projects !

My variable init is 

public string[] projects = new string[] {"","","" };

If I had 4 blank it loops 3 times but does not retrieve the 3 elements. If i init with 0 it fails


Any helps is much appreciated


Regards


5 Replies

GK Gayathri KarunaiAnandam Syncfusion Team November 2, 2021 02:26 AM UTC

Hi Mehdi, 

Thanks for contacting Syncfusion Support. 

We have checked your reported query. We are unable to replicate the reported issue. We have prepared a sample by using the mentioned value items. Please check the below sample. 

<SfListBox Scope="@scope2" DataSource="@groupA" TItem="ListItem" Height="330px" TValue="string[]" @attributes="listbox1Attr" @bind-Value="@projects"> 
                    <ListBoxFieldSettings Text="Name" Value="Name"></ListBoxFieldSettings> 
                    <ListBoxToolbarSettings Items="@items"></ListBoxToolbarSettings> 
                    <ListBoxTemplates TItem="ListItem"> 
                        <NoRecordsTemplate> 
                            <span>NO DATA AVAILABLE</span> 
                        </NoRecordsTemplate> 
                    </ListBoxTemplates> 
                </SfListBox> 
            </div> 
            <div class="dual-list-groupb"> 
                <h4>Group B</h4> 
                <SfListBox Scope="@scope1" DataSource="@groupB" Height="330px" TItem="ListItem" TValue="string[]" @attributes="listbox2Attr"> 
                    <ListBoxFieldSettings Text="Name" Value="Code"></ListBoxFieldSettings> 
                    <ListBoxTemplates TItem="ListItem"> 
                        <NoRecordsTemplate> 
                            <span>NO DATA AVAILABLE</span> 
                        </NoRecordsTemplate> 
                    </ListBoxTemplates> 
                </SfListBox> 
 
@code 
{ 
    public string[] projects = new string[] { "", "Australia","Germany","France" }; 
     
} 

For your reference, please check the sample. 


If you are still facing the issue, kindly share the below details. 

  • If possible, try to reproduce the reported issue in provided sample or share the issue reproducible sample.
  • If possible, please share the video demonstration of the issue.
  • Please share the Syncfusion version you are using.

Please provide the above requested information, based on that we will check and provide you a better solution quickly. 

Regards, 
Gayathri K 



ME Mehdi November 2, 2021 08:55 PM UTC

Hi

thank you for your sample

I uploaded an updated version

I was not clear I guess

What i try to do is to retrieve the list of items displayed in the 2nd listbox to save it to database.

I display in the console the list as a test but what is displayed is the list i set up, not the one updated in both listboxes

I can use your component to move item from one list to another, i can add items programmatically, but i cannot retrieve the items in the list once edited




Attachment: Listboxserver339155080_1e6ba877.zip


GK Gayathri KarunaiAnandam Syncfusion Team November 3, 2021 01:00 PM UTC

Hi Mehdi, 

We have checked your reported query. We can get the updated source in Listbox by using the GetDataList method. Please check the code snippet. 

protected async Task Display() 
    { 
        await ListBoxObj.AddItemsAsync(groupC); 
        var data = ListBoxObj.GetDataList(); 
 
         
    } 

For your reference, please check the sample link. 


Please check the API Reference link. 


Please get back to us, if you need further assistance. 

Regards, 
Gayathri K 



ME Mehdi November 7, 2021 06:47 PM UTC

THank you this is exactly what i needed



GK Gayathri KarunaiAnandam Syncfusion Team November 8, 2021 04:55 AM UTC

Hi Mehdi, 

Thanks for the update. 

We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this. 

Regards, 
Gayathri K 


Loader.
Up arrow icon