1

I have a problem with asp:dropdownlist when I try to change selected value to some thing using jquery after set the value, dropdownlist shows me last value and does not update to new selected value that have been set by me.

I try it(my html code)

<select name="ctl00$cphMain$ddlBankList" id="ddlBankList">
 <option value="2">a</option>
 <option value="67">b</option>
 <option value="85">c</option>
 <option value="175">d</option>
 <option value="84">e</option>
    <option value="86">f</option>
</select>

and to modify html i use this js

$("#<%=ddlBankList.ClientID%> option:selected").removeAttr("selected");
$("#<%=ddlBankList.ClientID%> option[value='67']").attr('selected', 'true');

But dropdownlist does not Jump to 67 value.

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Try using prop $("#<%=ddlBankList.ClientID%> option[value='67']").attr('selected', true); – Adil May 27 '15 at 10:14
  • tax for your answer. when i call alert($("#<%=ddlBankList.ClientID%> option:selected").val()); shows that my value set to 67 but dropdownlist does not jump to value in UI – Matin Shokri May 27 '15 at 10:27
  • possible duplicate of [How can I set the value of a DropDownList using jQuery?](http://stackoverflow.com/questions/292615/how-can-i-set-the-value-of-a-dropdownlist-using-jquery) – Liam May 27 '15 at 10:28
  • tnx Liam. to that post said dont forget to use .selectmenu('refresh') after set value but i get error when i use it – Matin Shokri May 27 '15 at 10:57

2 Answers2

1

use this

$("#ddlBankList").val(67);

JSFIDDLE

Ashish Bhagat
  • 409
  • 3
  • 16
1

You can use Jquery val function directly for select option in dropdown.

$("#<%=ddlBankList.ClientID%>").val('67');
Manish Parakhiya
  • 3,732
  • 3
  • 22
  • 25
  • tnx for your answer. when i call alert($("#<%=ddlBankList.ClientID%> option:selected").val()); shows that my value set to 67 but dropdownlist does not jump to value in UI – Matin Shokri May 27 '15 at 10:33