Before proceeding, please go through my previous articles:
- ASP.NET WEB API with Entity Framework 6 code first technique- Part I
- ASP.NET WEB API with Entity Framework 6 code first technique- Part 2
- GET: api/department
- api/employees/{department id}
GET: api/department response as shown in figure 1.
GET:api/employees/{department id} response as shown in
figure 2.
From the above images you can observe that api/department API gives the detail about the department and api/employees/{department id} API gives the details about the employee by relating employees and department entity which is achieved by DTO's. Please refer the following again,
HTML design
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.default.min.css" />
- <script src="http://cdn.kendostatic.com/2014.3.1316/js/jquery.min.js"></script>
- <script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.all.min.js"></script>
- <script src="http://cdn.kendostatic.com/2014.3.1029/js/jszip.min.js"></script>
- <title></title>
- <meta charset="utf-8" />
- </head>
- <body>
- <div >
- <div id="grid"></div>
- <div id="grid1"></div>
- </div>
- </body>
- </head>
- </html>
- $(document).ready(function () {
- var test=1;
- function onChange() {
- if(this.select())
- {
- var selected = $.map(this.select(), function (item) {
- return $(item).text();
- });
- test = selected.join(",");
- var grid = $('#grid1').data('kendoGrid');
- grid.dataSource.transport.options.read.url = "/api/Employees/" + test
- grid.dataSource.read();
- grid.refresh();
- }
- else
- alert("fail")
- }
- $("#grid").kendoGrid({
- dataSource: {
- transport: {
- read: {
- url: "/api/Departments",
- dataType: "json"
- }
- },
- pageSize: 20
- },
- height: 350,
- change: onChange,
- selectable: "multiple cell",
- pageable: true,
- sortable: true,
- columns: [
- {
- field: "DepartmentID",
- title: "Department ID"
- },
- {
- field: "DepartmentName",
- title: "Department Name",
- },
- ]
- });
- $("#grid1").kendoGrid({
- dataSource: {
- transport: {
- read: {
- url: "/api/Employees/" + test,
- dataType: "json"
- }
- },
- pageSize: 20
- },
- height: 350,
- change: onChange,
- selectable: "multiple cell",
- pageable: true,
- sortable: true,
- columns: [
- {
- field: "EmployeeID",
- title: "Employee ID"
- },
- {
- field: "FirstName",
- title: "First Name",
- },
- {
- field: "LastName",
- title: "Last Name",
- },
- {
- field: "Department.DepartmentName",
- title: "Department Name",
- },
- ]
- });
- });
From the above code you can observe, in the onChange event we are fetching the selected value of the department grid and read the data source of the Employee grid to populate the Employee grid based on department selected in Department grid.
The result in browser
I hope you have enjoyed this article. Your valuable feedback, question, or comments about this article are always welcomed.

Arul RPosted Jan 17, 2016, 10:48 AM
Thanks for nice article
Gowtham KPosted Jan 6, 2016, 10:45 AM
Hi Sepinoud, can you please elaborate your question i'm unable to get it
Humayun Kabir MamunPosted Dec 28, 2015, 1:41 AM
Nice...
Santhakumar MunuswamyPosted Dec 27, 2015, 8:59 AM
Thanks for nice article
Sibeesh VenuPosted Dec 26, 2015, 10:47 AM
Nice Share
Banketeshvar NarayanPosted Dec 26, 2015, 5:53 AM
Good One
Raja TPosted Dec 26, 2015, 5:43 AM
Nice, Thank for sharing
Rupali ShindePosted Dec 26, 2015, 5:11 AM
really useful article sir
Sridhar SharmaPosted Dec 26, 2015, 4:33 AM
Nice Share