1. First Add WebService in your Asp.net WebApplication and Name Employees:

File >> New >> Project >> Web>> Asp.netWebAppliCation : then follow the figure:

Figure 1

Figure 2

2. You will find it in App Code Folder:

Figure 3

3.
Open The Employees.asmx and add a class name EMPLOYEES and ADD some employees in it(List OF Employees) below Employee constructor:


Figure 4

Figure 5

4. Now Add Two Web Methods GetAllEmployees () and GetEMployeesByEmpCode() below List Of Employees:

Figure 6

5. Now Go To the Design Page Default.aspx and add the code given below:
  1. <input type="button" id="getemployees" value="Get Employees" onclick="getEmployees();" />
  2. <div id="output" style="overflow: scroll">
  3. </div>
  4. <input type="button" id="getemployeesbyempcode" value="Get Employees By Code" onclick="GetEmployeesByEmpCode();" />
  5. </br> Select Emp Code:<div id="Div1">
  6. <select id="ddlemployees" onchange="GetEmployeesByEmpCode();">
  7. </select>
  8. </div>
6. Add jquery reference on site.master
  1. <script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
7. Now Create a Jquery Function to getEmployees() under Head tag in site.Master:
  1. function getEmployees() {
  2. $.ajax({
  3. type: "POST",
  4. url: "Employees.asmx/GetAllEmployees",
  5. data: "{}",
  6. contentType: "application/json; charset=utf-8",
  7. dataType: "json",
  8. success: function (response) {
  9. var Employees= response.d;
  10. $('#output').empty();
  11. $('#output').append('<table id="tbone"><thead><tr><th style="width:60px">EMPLOYENAME</th><th style="width:60px">EMPCODE</th><th style="width:60px">GENDER</th></tr></thead></table>');
  12. $.each(Employees, function (index, Employee) {
  13. var Name = "empname";
  14. var EmpCode = "empcode";
  15. var Gender = "gender";
  16. $('#output').append('<table><tr><td style="width:60px">' + Employee.empname + '</td><td style="width:60px">' + Employee.empcode + '</td><td style="width:60px">' + Employee.gender + '</td></tr>');
  17. });
  18. },
  19. failure: function (msg) {
  20. $('#output').text(msg);
  21. }
  22. });
  23. }
8. Now Create a Jquery Function to GetEmployeesByEmpCode() under Head tag in site.Master:
  1. function GetEmployeesByEmpCode() {
  2. $.ajax({
  3. type: "POST",
  4. url: "Employees.asmx/GetEmployeesByEmpCode",
  5. data: "{empcode:" + $('#ddlemployees').val() + "}",
  6. contentType: "application/json; charset=utf-8",
  7. dataType: "json",
  8. success: function (response) {
  9. var Employees = response.d;
  10. $('#output').empty();
  11. $('#output').append('<table id="tbone"><thead><tr><th style="width:60px">EmployeeName</th><th style="width:60px">EmpCode</th><th style="width:60px">Gender</th><th style="width:60px">DOORS</th></tr></thead></table>');
  12. $.each(Employees, function (index, Employee) {
  13. $('#output').append('<table><tr><td style="width:60px">' + Employee.empname + '</td><td style="width:60px">' + Employee.empcode + '</td><td style="width:60px">' + Employee.gender + '</td></tr>');
  14. });
  15. },
  16. failure: function (msg) {
  17. $('#output').text(msg);
  18. }
  19. });
OUTPUT after pressing get all employees:

Figure 7
OUTPUT after Selecting empcode from dropdownlist::

Figure 8