c# - select dropdownlist value with jquery -
i trying set value of dropdownlist jquery. i've tried few solutions site none of them work solution. have:
$(document).on("click", ".open-editcontract", function () { var id = $(this).data('id'); $('#<%=ddltsaidedit.clientid%>').val(id); $('#editcontract').modal('show'); });
also in backend have code populates dropdown on page_load event:
dictionary<string, string> dict = new dictionary<string, string>(); dict.clear(); dict = util.tsaidforcontract(convert.toint32(request.querystring[0])); ddltsaidedit.datasource = dict; ddltsaidedit.datatextfield = "value"; ddltsaidedit.datavaluefield = "key"; ddltsaidedit.databind(); ddltsaidedit.items.insert(0, new listitem("-- select tsa id --", "0"));
i have in gridview action triggers modal popup shown:
<asp:templatefield headertext="edit"> <itemtemplate> <a style="text-decoration:none;" class="btn btn-info open-editcontract" data-id='<%#eval("id") %>' href="#"><i class="icon-edit icon-white"></i></a> </itemtemplate> </asp:templatefield>
setting values textboxes works fine method not dropdowns, give advice. can see value in source , when alert(id) in js can see value in messagebox. every advice welcomed. thanks
add function:
function setdropdownlist(ddl, value) { var = document.getelementbyid(dropdownlist); (i = 0; < a.length; i++) { if (a.options[i].value == value) { a.selectedindex = i; } } }
and set dropdown value this:
var id = $(this).data('id'); setdropdownlist('<%=ddltsaidedit.clientid %>', id)
this works me. make sure getting valid value id
, putting alert, or checking in console.log
.
Comments
Post a Comment