I have a ASP.NET MVC razor listbox that is generated using the following code :-
@Html.EJS().ListBox("selectTABToNavigateTo").Scope("combined-list").Height("500px").Change("onSelectTabNavigation").Fields(new Syncfusion.EJ2.DropDowns.ListBoxFieldSettings { Text = "Label", Value = "Id" }).DataSource((IEnumerable<CustomFormElement>)ViewBag.selectedTabbedFieldList).SelectionSettings(new Syncfusion.EJ2.DropDowns.ListBoxSelectionSettings { Mode = Syncfusion.EJ2.DropDowns.SelectionMode.Single}).Render()
This all renders fine and is usable, however, I want to be able to preselect an item, where this will be done in JavaScript.
var tabSelect = document.getElementById("selectTABToNavigateTo").ej2_instances[0];
tabSelect.selectItems([]);
if (currentlySelectedTabNavigation !== undefined) {
var tabSelectListData = document.getElementById("selectTABToNavigateTo").ej2_instances[0].listData;
var count = 0;
for (const item of tabSelectListData) {
if (item.RecordId == currentlySelectedTabNavigation) {
var theSelectedItems = [item];
tabSelect.selectItems(theSelectedItems);
}
}
}
I have tried to create a list of Ids and a list of objects nothing seems to work. What I will say is that if I do select something in the listbox, dismiss the box and then try to look at the listbox again, the item that I have selected is selected and not the item I want pre-selected.
Any help with this will be greatly appreciated.
Thank you