Plugin Select2 Is always selecting the first option in ASP.NET

I have been searching for a couple of hours to try to fix this. I am using the Select2 jquery plugin to get a dropdown with multiple select.

enter image description here

The problem is that the first option is always selected. I have tried to use the tag multiple="multiple" but ASP.NET doesn't know what is that, only allow me to make it multiple="true" or multiple="false"

enter image description here

Any suggestion??

Upvotes: 0

Views: 785

Answers (1)

risteb
risteb

Reputation: 21

By default Select2 should not be preselecting any value, so my guess is that you are setting the selected value somewhere, probably in the c# code where you are populating the drop down with values. So try to clear the selected index in the Page_Load method slEmployeeRole.SelectedIndex = -1 or in the js document ready part of the page, try clearing the drop down just to be sure that nothing is selected. And use multiple="true". $('#slEmployeeRole').val(null).trigger('change');

Upvotes: 1

Related Questions