is there a way to preselect a value in the listview element

I have a listview element that I need to set up with preselected items in certain situations. I saw a Blazor example of doing something like this and wondered if there was an asp.net core example or if it was possible.

I should have also stated this is a multi select listview with checkbox enabled

1 Reply 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team October 12, 2020 06:21 AM UTC

Hi Tim Smith,  
 
Greetings from Syncfusion support. 
 
We have checked your requirement with ListView component. You can pre-select an list item by using selectMultipleItems method of ListView component.  
 
Refer the below code snippet. 
 
<ejs-listview id="listview" dataSource="ViewBag.dataSource" showHeader="true" headerTitle="Device settings" actionComplete="actionComplete"> 
    <e-listview-fieldsettings id="id" text="Name"> 
    </e-listview-fieldsettings> 
</ejs-listview> 
<script> 
    function actionComplete() { 
        var listview = document.getElementById("listview").ej2_instances[0]; 
        var data = [{ id: "list-01" }, {id: "list-02"}] 
        // you can select the item using select item method.  
        listview.selectMultipleItems(data);   
    } 
</script> 
 
 
Please, download the sample from the following link. 
 
 
Refer the below link for ListView component. 
 
 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Marked as answer
Loader.
Up arrow icon