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 = "USA" });
customers.Add(new Customer { CustomerId = 2, Name = "Mudassar Khan", Country = "India" });
customers.Add(new Customer { CustomerId = 3, Name = "Elizabeth Lincoln", Country = "Canada" });
return Json(customers, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCountryName()
{
List<SelectListItem> countries = new List<SelectListItem>();
countries.Add(new SelectListItem { Text = "USA", Value = "USA" });
countries.Add(new SelectListItem { Text = "India", Value = "India" });
countries.Add(new SelectListItem { Text = "Canada", Value = "Canada" });
return Json(countries, JsonRequestBehavior.AllowGet);
}
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Country { 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) {
$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 class="dropDownTemplate"/>' +
'<span id="lblCountry" style="color:red;display:none;" > Select Country!</span>'
},
],
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('.dropDownTemplate');
$(ddlCountries).kendoDropDownList({
dataSource: $scope.ddlDataSource = {
transport: { read: { url: "/Home/GetCountryName" } }
},
optionLabel: "Select Country",
dataTextField: "Text",
dataValueField: "Value",
value: dataItem.Country
});
});
}
};
$scope.Save = function () {
var grid = $("#tblGrid").data("kendoGrid");
for (var i = 0; i < grid.dataSource.data().length; i++) {
var country = $("#tblGrid").data("kendoGrid").tbody.find('tr').eq(i).find('.k-input').html();
if (country == "Select Country") {
$("#tblGrid").data("kendoGrid").tbody.find('tr').eq(i).find('#lblCountry').show();
} else {
$("#tblGrid").data("kendoGrid").tbody.find('tr').eq(i).find('#lblCountry').hide();
}
}
};
})
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" id="tblGrid"></kendo-grid>
<br />
<input type="button" name="name" value="Save" ng-click="Save()" />
</body>
</html>
Screenshot