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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Add new item to listbox with a template

Thread ID:





146751 Aug 17,2019 03:21 PM UTC Aug 19,2019 12:32 PM UTC jQuery 1
Tags: ejListBox
Asked On August 17, 2019 03:21 PM UTC


I have the following code which upon an ajax save add the new saved item to a listbox.  Below is my code:
                    $('#inclusions').ejListBox("addItem", data.inclusionText);
                    var newInclusion = $('#inclusions li:last-child').find('.ename');
                    $(newInclusion).attr("id", data.newInclusionId);
                    $(newInclusion).attr('data-typevalue', 0);

My listbox has the following template:
@Html.EJ().ListBox("defaultInclExcl").Width("100%").Datasource(Model.DefaultEIList).ListBoxFields(incl => incl.Text("Label").Value("TypeOfInclusionId").ID("Id")).AllowDrag(true).AllowDrop(false).Enabled(true).Template("<span class='e-icon eimg'></span><div class='ename' style='word-break:break-word' id=${Id} data-typevalue=${TypeOfInclusionId}> ${Label} </div>").ClientSideEvents(e => e.ItemDrag("GetIndex")).ClientSideEvents(e => e.ItemDragStop("validateDrag"))

The new item is being added correctly with the template, however, my previously added item of the listbox are getting the values  data-typevalue and id as undefined.
I have noticed that it is when the code hits the first line, that is the addItem, which is setting the two values to undefined.

Any help please?


Ashokkumar Balasubramanian [Syncfusion]
Replied On August 19, 2019 12:32 PM UTC

Hi Alis, 
Good day to you. 
We have checked your query about the ListBox component, we were unable to reproduce this issue. we suggest you find the exact li element and then add the attributes. it will be working fine, Id and data-typevalue was added correctly please refer the below screenshot. 
kindly check the below sample, 
If you are facing any issues kindly modify this sample to reproduce the issue so that we can proceed further. 
Ashokkumar B. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon