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 = "John Hammond", Country = "United States" });
customers.Add(new Customer { CustomerId = 2, Name = "Mudassar Khan", Country = "India" });
customers.Add(new Customer { CustomerId = 3, Name = "Suzanne Mathews", Country = "France" });
customers.Add(new Customer { CustomerId = 4, Name = "Robert Schidner", Country = "Russia" });
return Json(customers, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCountryName()
{
List<SelectListItem> countries = new List<SelectListItem>();
countries.Add(new SelectListItem { Text = "United States", Value = "United States" });
countries.Add(new SelectListItem { Text = "India", Value = "India" });
countries.Add(new SelectListItem { Text = "France", Value = "France" });
countries.Add(new SelectListItem { Text = "Russia", Value = "Russia" });
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) {
ApplyKendoGrid();
$scope.Save = function () {
var grid = $("#tblGrid").data("kendoGrid");
var rows = [];
for (var i = 0; i < grid.dataSource.data().length; i++) {
var row = {};
row.Id = $(grid.dataSource.data()[i])[0].CustomerId;
row.Name = $(grid.dataSource.data()[i])[0].Name;
row.Country = $("#tblGrid").data("kendoGrid").tbody.find('tr').eq(i).find('.k-input').html();
rows.push(row);
}
alert(JSON.stringify(rows));
};
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 class="dropDownTemplate" style="width:100px"/>'
},
],
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: {
transport: {
read: { url: "/Home/GetCountryName" }
}
},
dataTextField: "Text",
dataValueField: "Value",
value: dataItem.Country
});
});
}
};
}
})
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" id="tblGrid"></kendo-grid>
<input type="button" name="name" value="Save" ng-click="Save()" />
</body>
</html>
Screenshot