The following is the table in design mode.

table design
Figure 1

The following is the script of my table:

  1. CREATE TABLE [dbo].[EmployeeTeam](
  2. [Employee_ID] [int] IDENTITY(1,1) NOT NULL,
  3. [Name] [varchar](50) NULL,
  4. [Manager_ID] [int] NULL,
  5. [Email] [varchar](50) NULL,
  6. [Mobile] [varchar](50) NULL,
  7. [Country] [varchar](50) NULL,
  8. [IsManager] [bit] NULL,
  9. CONSTRAINT [PK_EmployeeTeam] PRIMARY KEY CLUSTERED
  10. (
  11. [Employee_ID] ASC
  12. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  13. ) ON [PRIMARY]
  14. GO
  15. SET ANSI_PADDING OFF
  16. GO
The following is the data in my table:

Data in My Table
Figure 2.

Here in this you can see I have employee records with its Manager Id. So in the drop down I will see only Manage and on selecting Manager from the drop down I will show their team information in the GridView.

Now create a Visual Studio solution as in the following:

create a Visual Studio Solution
Figure 3

Now add a jQuery reference. For that, right-click on the project in Solution Explorer and click Manage NuGet Packages.

manage nuGet Packages
Figure 4

jQuery install
Figure 5

install
Figure 6

jQuery package
Figure 7

Now add a new class to your project's EmployeeDetails.cs with the following code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace jQueryDropDownGridViewDemo
  6. {
  7. public class EmployeeDetails
  8. {
  9. public int Employee_ID { get; set; }
  10. public string Name { get; set; }
  11. public int Manager_ID { get; set; }
  12. public string Email { get; set; }
  13. public string Mobile { get; set; }
  14. public string Country { get; set; }
  15. }
  16. }
EmployeeDetails
Figure 8

The following is my aspx:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jQueryDropDownGridViewDemo.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="Scripts/jquery-2.1.4.min.js"></script>
  7. <script type="text/javascript">
  8. $(document).ready(function () {
  9. $.ajax({
  10. type: "POST",
  11. contentType: "application/json; charset=utf-8",
  12. url: "Default.aspx/BindAllManager",
  13. data: "{}",
  14. dataType: "json",
  15. success: function (data) {
  16. $("#ddlManager").append($("<option></option>").val('0').html("-- Select Manager --"));
  17. $.each(data.d, function (key, value) {
  18. $("#ddlManager").append($("<option></option>").val(value.Employee_ID).html(value.Name));
  19. });
  20. },
  21. error: function (result) {
  22. alert("Error");
  23. }
  24. });
  25. //Capturing Selection Index change of Manager Drop Down List
  26. $('#ddlManager').change(function () {
  27. var SelectedText = $(this).find(":selected").text();
  28. var SelectedValue = $(this).val();
  29. if (SelectedValue == "0")
  30. {
  31. $('#dvRecords').empty();
  32. alert("Please Select Manager");
  33. return false;
  34. }
  35. $('#dvRecords').empty();
  36. var JSONObject = { "ManagerID": SelectedValue };
  37. var jsonData = JSON.stringify(JSONObject);
  38. //Filling Grid View
  39. $.ajax({
  40. type: 'POST',
  41. contentType: "application/json; charset=utf-8",
  42. url: 'Default.aspx/BindManagerEmployee',
  43. data: jsonData,
  44. dataType: 'JSON',
  45. success: function (response) {
  46. $('#dvRecords').append("<table style='width:100%;'><tr><td></td></tr><tr style='background-color:orange; color:white;'><th style='width:100px; text-align:center;'>Employee ID </th><th style='width:160px; text-align:center;'>Name </th><th style='width:160px; text-align:center;'>Email </th><th style='width:50px; text-align:right; padding-right:70px;'>Mobile </th><th style='width:130px; text-align:left;'>Country </th></tr>")
  47. for (var i = 0; i < response.d.length; i++) {
  48. $('#dvRecords').append("<tr style='background-color:yellow; font-family:verdana; font-size:12pt;'><td style='width:140px;'>" + response.d[i].Employee_ID + "</td><td style='width:200px;'>" + response.d[i].Name + "</td><td style='width:220px;'>" + response.d[i].Email + "</td><td style='width:140px; text-align:left;'>" + response.d[i].Mobile + "</td><td style='width:120px; text-align:left;'>" + response.d[i].Country + "</td></tr>")
  49. }; $('#dvRecords').append("</table>")
  50. },
  51. error: function () {
  52. alert("Error");
  53. }
  54. });
  55. });
  56. return false;
  57. });
  58. </script>
  59. </head>
  60. <body>
  61. <form id="form1" runat="server">
  62. <table style="width: 100%; background-color: skyblue; border: solid 10px Red; padding: 10px;">
  63. <tr>
  64. <td colspan="2" style="height: 40px; background-color: red; color: white; font-family: Verdana; font-size: 17pt; font-weight: bold; text-align: center;">jQuery: Showing Records On Selecting Value From Drop Down List
  65. </td>
  66. </tr>
  67. <tr style="height: 40px; background-color: greenyellow; color: blue; font-family: Verdana; font-size: 14pt; text-align: center;">
  68. <td>
  69. <asp:Label ID="lnlManager" runat="server" Text="Select Manager => "></asp:Label></td>
  70. <td>
  71. <asp:DropDownList ID="ddlManager" runat="server" Font-Bold="true" Width="200px" Height="30px"></asp:DropDownList>
  72. </td>
  73. </tr>
  74. <tr>
  75. <td></td>
  76. </tr>
  77. <tr>
  78. <td colspan="2">
  79. <div id="dvRecords" runat="server"></div>
  80. </td>
  81. </tr>
  82. </table>
  83. </form>
  84. </body>
  85. </html>
Here is the aspx.cs code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Services;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Data.SqlClient;
  10. using System.Configuration;
  11. namespace jQueryDropDownGridViewDemo
  12. {
  13. public partial class Default : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. }
  18. [WebMethod]
  19. public static EmployeeDetails[] BindAllManager()
  20. {
  21. List<EmployeeDetails> details = new List<EmployeeDetails>();
  22. DataTable dtManager = new DataTable();
  23. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPCON"].ConnectionString))
  24. {
  25. SqlCommand cmd = new SqlCommand();
  26. SqlDataAdapter da = new SqlDataAdapter();
  27. cmd = new SqlCommand("Select * from EmployeeTeam WHERE IsManager=1", con);
  28. da.SelectCommand = cmd;
  29. da.Fill(dtManager);
  30. }
  31. foreach (DataRow dtrow in dtManager.Rows)
  32. {
  33. EmployeeDetails logs = new EmployeeDetails();
  34. logs.Employee_ID = Convert.ToInt32(dtrow["Employee_ID"].ToString());
  35. logs.Name = dtrow["Name"].ToString();
  36. details.Add(logs);
  37. }
  38. return details.ToArray();
  39. }
  40. [WebMethod]
  41. public static List<EmployeeDetails> BindManagerEmployee(int ManagerID)
  42. {
  43. List<EmployeeDetails> details = new List<EmployeeDetails>();
  44. DataTable dtManager = new DataTable();
  45. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPCON"].ConnectionString))
  46. {
  47. SqlCommand cmd = new SqlCommand();
  48. SqlDataAdapter da = new SqlDataAdapter();
  49. cmd = new SqlCommand("Select * from EmployeeTeam WHERE Manager_ID='" + ManagerID + "'", con);
  50. da.SelectCommand = cmd;
  51. da.Fill(dtManager);
  52. }
  53. foreach (DataRow dtrow in dtManager.Rows)
  54. {
  55. EmployeeDetails logs = new EmployeeDetails();
  56. logs.Employee_ID = Convert.ToInt32(dtrow["Employee_ID"].ToString());
  57. logs.Name = dtrow["Name"].ToString();
  58. logs.Email = dtrow["Email"].ToString();
  59. logs.Mobile = dtrow["Mobile"].ToString();
  60. logs.Country = dtrow["Country"].ToString();
  61. details.Add(logs);
  62. }
  63. return details;
  64. }
  65. }
  66. }
I defined my connection string in the web.config file as in the following:
  1. <?xml version="1.0"?>
  2. <!--
  3. For more information on how to configure your ASP.NET application, please visit
  4. http://go.microsoft.com/fwlink/?LinkId=169433
  5. -->
  6. <configuration>
  7. <system.web>
  8. <compilation debug="true" targetFramework="4.5" />
  9. <httpRuntime targetFramework="4.5" />
  10. </system.web>
  11. <connectionStrings>
  12. <add name="EMPCON" connectionString="Data Source=INDIA\MSSQLServer2k8;Initial Catalog=TestDB;Integrated Security=True"/>
  13. </connectionStrings>
  14. </configuration>
code
Figure 9

Now run your application:

select value
Figure 10

select manager name
Figure 11

showingt record
Figure 12

select manager
Figure 13

emp id
Figure 14

jQuery
Figure 15