Binding listbox and dropdown list using javascript - ASP.NET
we call a web service that return list<Employee> .
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../WebServices/servicename.asmx/methodname",
data: JSON.stringify({}),
dataType: "json",
success: BindEmployeeSucceeded,
error: BindEmployeeFailed
});
function BindEmployeeSucceeded(result) {
var columns = result.d;
$('#<%=lbEmployee.ClientID %>').empty();
$('#<%=
.ClientID %>').append('<option value="' + "0" + '">' + "Select" + '</option>');
lbEmployee
for (var i = 0; i < columns.length; i++) {
$('#<%=
.ClientID %>').append('<option value=' + columns[i].Id + '>' + columns[i].OrganisationName + '</option>');
lbEmployee
}
}
function BindEmployeeFailed() {
}
note: OrganisationName and Id are properties of Employee