User1487175000 posted
Hi,
I populate a list box with jquery after that i want to select a option dynamically by value. But i havent successed.
Here is list
<asp:ListBox ID="listOfOpenBills" runat="server" Width="95%" Height="50px" CssClass="openBill"></asp:ListBox>
At page load populate list
function getOpenBilllist() {
$(function () {
$.ajax({
type: "POST",
url: "businessLounge.aspx/getOpenBillList",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var openbillList = $('.openBill');
openbillList.empty();
$.each(r.d, function () {
openbillList.append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function () {
alert("Error");
}
});
});
}
Script: this method add the article in the bill and getOpenBilllist(); method re-populate the list to get latest list of open bills.
function addArticleToBill(articleID) {
$(function () {
var uid = $("#<% = uID.ClientID %>").val();
var contactPersonID = getContactPersonID();
if (typeof contactPersonID == "undefined") {
alert("Please Select Contact Person");
} else {
$.ajax({
type: "POST",
url: "businessLounge.aspx/addArticleInBill",
data: "{'articleID':'" + articleID + "','contactPersonID':'" + contactPersonID + "','uid':'" + uid + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
getBill(contactPersonID, '');
getOpenBilllist();
$('.openBill').val(contactPersonID);
},
error: function () {
alert("Error");
}
});
}
});
}
Problem:
In success after re-populate the list i want to select the option in the list $('.openBill').val(contactPersonID); but option is not selected. Option is in the list. I dont know it not selected by my code. There is no error in debug window as well.
Thanks in advance
/Shahid