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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting selectedItemIndex programmatically

Thread ID:





117488 Oct 29,2014 05:16 PM UTC Nov 3,2014 12:06 PM UTC JavaScript 3
Tags: ejDropDownList
Randy Craven
Asked On October 29, 2014 05:16 PM UTC


My MVC project uses a (javascript) dropDownList with Json data source.  When loading the view I would like to assign the selectedItemIndex  if a previous selection was made, or have the list be empty (null selected value) if no selection has been made.  Something like this:

    int index = -1;
    if(Model.previouslySelectedIndex > -1){
        index = Model.previouslySelectedIndex;

        dataSource: myJson,
        selectedItemIndex: Number(@index)

It appears that using -1 for the selectedItemIndex does not work;  the selectedItemIndex appears to be set to 0 instead.  Using null throws an error.

I also tried using the MVC wrapper and it appears that you can successfully assign the value of -1.   However, for other reasons I need to use the plain javascript controls.

Can anyone suggest the best way to accomplish this?

thank you,

Kasithangam C [Syncfusion]
Replied On October 30, 2014 02:58 PM UTC

Hi Randy,

Sorry for the inconvenience caused. We are able to reproduce the specified issue. We have confirmed this as bug (“while setting the “selectedItemIndex” property value as -1 in dropdownlist, the dropdown value must be an empty and while setting the “selectedItemIndex” property as null, it throws an error.”) and an issue report has been logged on this. If you are in need of a solution sooner we can also provide a custom patch for this within 15days.

As a workaround solution, Instead of specify the “selectedItemIndex” property value in the control creation, we have set the index variable value as -1 and checked the condition with that value. In this, we have to manually empty the dropdown value when the index variable value -1 otherwise the index value is set to the “selectedItemIndex” property as shown below,


   <script type="text/javascript">

        var target;

        $(function () {

           var index = -1;

           var target = $("#bikeList").data("ejDropDownList");

            if (index > -1)



                target.option("value", "");


Also we have prepared the sample based on this and it is available under the following location,

Sample location: Sample

Kindly let us know if you have any queries.



Randy Craven
Replied On October 30, 2014 07:57 PM UTC

Hello Kasithangam,

Thank you for this reply.  The workaround you posted is sufficient for me and a custom patch is not necessary.

I'm glad it was a real bug and not an imagined one.

Thanks again,

Saranya Sivakumar [Syncfusion]
Replied On November 3, 2014 12:06 PM UTC

Hi Randy,
Thanks for your update.
We are glad to hear that the issue has been resolved in your side. 
Please let us know if you have further concern.


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