Problem
I guess the problem here is, the
option
is not present inside the
DropDownList
.
So, the below code should work for you, if you already have the
temp
option
.
$("#dptcentres_edit > [value=" + temp + "]").attr("selected", "true");
Solution
If you don't have the
option
inside the
DropDownList
, then you need to append that first and then select it.
So, the below code is what you need.
var newOption = $('<option>');
newOption.attr('value', temp).text(temp);
$('#dptcentres_edit').append(newOption);
$("#dptcentres_edit > [value=" + temp + "]").attr("selected", "true");
Demo
[Demo] Dynamically Set and Select the DropDown Option[
^]