Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public JsonResult GetCustomers()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { CustomerId = 1, Name = "Fran Wilson", Country = "1", State = "3" });
customers.Add(new Customer { CustomerId = 2, Name = "Mudassar Khan", Country = "2", State = "4" });
customers.Add(new Customer { CustomerId = 3, Name = "Elizabeth Lincoln", Country = "3", State = "8" });
return Json(customers, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCountryName()
{
List<SelectListItem> countries = new List<SelectListItem>();
countries.Add(new SelectListItem { Text = "USA", Value = "1" });
countries.Add(new SelectListItem { Text = "India", Value = "2" });
countries.Add(new SelectListItem { Text = "Canada", Value = "3" });
return Json(countries, JsonRequestBehavior.AllowGet);
}
public JsonResult GetStateName(string country)
{
List<SelectListItem> states = new List<SelectListItem>();
if (country == "2")
{
states.Add(new SelectListItem { Text = "Maharashtra", Value = "4" });
states.Add(new SelectListItem { Text = "Gujarat", Value = "5" });
states.Add(new SelectListItem { Text = "Goa", Value = "6" });
}
else if (country == "1")
{
states.Add(new SelectListItem { Text = "Alabama", Value = "1" });
states.Add(new SelectListItem { Text = "Arizona", Value = "2" });
states.Add(new SelectListItem { Text = "Alaska", Value = "3" });
}
else if (country == "3")
{
states.Add(new SelectListItem { Text = "Ontario", Value = "7" });
states.Add(new SelectListItem { Text = "Quebec", Value = "8" });
states.Add(new SelectListItem { Text = "Manitoba", Value = "9" });
}
return Json(states, JsonRequestBehavior.AllowGet);
}
public JsonResult GetPopulations(string state)
{
string populations = "";
if (state == "4")
{
populations = "4848848448";
}
else if (state == "5")
{
populations = "544848848";
}
else
{
populations = "3444444";
}
return Json(populations, JsonRequestBehavior.AllowGet);
}
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public string State { get; set; }
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.1.114/styles/kendo.default-v2.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/angular.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/kendo.all.min.js"></script>
<script type="text/javascript">
var app = angular.module("MyApp", ["kendo.directives"]);
app.controller("MyController", function ($scope, $http) {
ApplyKendoGrid();
function ApplyKendoGrid() {
$scope.mainGridOptions = {
dataSource: { transport: { read: "/Home/GetCustomers/" }, pageSize: 5 },
pageable: { refresh: true, pageSizes: [2, 25, 50] },
groupable: false,
sortable: true,
columns: [
{ field: "CustomerId", title: "Id", width: 40 },
{ field: "Name", title: "Name", width: 150 },
{
field: "Country",
template: '<input style="width:120px" class="k-state-default CountryDropDown" />',
width: 150
},
{
field: "State",
template: '<input style="width:120px" class="k-state-default StateDropDown" />',
width: 150
},
{
field: "Population",
template: '<input style="width:120px" class="k-textbox k-state-disabled PopulationText" />',
width: 150
}
],
dataBound: function (e) {
var grid = e.sender;
var items = e.sender.items();
items.each(function (e) {
var dataItem = grid.dataItem(this);
var ddlCountries = $(this).find('.CountryDropDown');
$(ddlCountries).kendoDropDownList({
dataSource: {
transport: { read: { url: "/Home/GetCountryName" } }
},
optionLabel: "Select Country",
dataTextField: "Text",
dataValueField: "Value",
value: dataItem.Country,
filter: "contains",
minLength: 2,
change: function (e) {
$(ddlStates).kendoDropDownList({
dataSource: {
transport: {
read: {
url: "/Home/GetStateName",
data: { country: this.value() }
}
}
},
optionLabel: "Select State",
dataTextField: "Text",
dataValueField: "Value",
filter: "contains",
minLength: 2,
change: function (e) {
$http({
method: 'Post',
url: '/Home/GetPopulations/',
params: { state: this.value() }
}).then(function (response) {
$(e.sender.element).closest('tr').find('.PopulationText').val(response.data);
});
}
}).data("kendoDropDownList");
}
});
var ddlStates = $(this).find('.StateDropDown');
$(ddlStates).kendoDropDownList({
dataSource: {
transport: {
read: {
url: "/Home/GetStateName",
data: { country: dataItem.Country }
}
}
},
optionLabel: "Select State",
dataTextField: "Text",
dataValueField: "Value",
value: dataItem.State,
filter: "contains",
minLength: 2,
change: function (e) {
$http({
method: 'Post',
url: '/Home/GetPopulations/',
params: { state: this.value() }
}).then(function (response) {
$(e.sender.element).closest('tr').find('.PopulationText').val(response.data);
});
}
});
});
}
};
}
})
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" style="height:230px"></kendo-grid>
</body>
</html>
Screenshot