Saturday 7 January 2012


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();
            $('#<%=
lbEmployee
.ClientID %>').append('<option value="' + "0" + '">' + "Select" + '</option>');
            for (var i = 0; i < columns.length; i++) {
                $('#<%=
lbEmployee
.ClientID %>').append('<option value=' + columns[i].Id + '>' + columns[i].OrganisationName + '</option>');
            }
        }

        function BindEmployeeFailed() {

        }

note: OrganisationName and Id are properties of Employee 

No comments:

Post a Comment