1

I am migrating my application form MVC Extension to the Telerik UI for ASP.NET MVC. Changed the grid to:

@(Html.Kendo().Grid((IEnumerable<vw_Client_info>)ViewBag.Clients) .Name("Clients") .Columns(columns => { columns.Bound(c => c.ClientID).Width(30).Title("Client ID").Hidden(); columns.Bound(c => c.FullName).Width(130); }) .DataSource(dataSource => dataSource .Ajax() .Model(model => model.Id(p => p.ClientID)) .Read(read => read.Action("AllClientsSelection", "Visit"))) .Selectable() .Events(events => { events.Change("onRowSelected"); }) .RowAction(row => row.Selected = row.DataItem.ClientID.Equals(ViewData["id"])) ) 

To get the cell value, I used before :

function onRowSelected(e) { var detailGrid = $('#Visit').data('tGrid'); id = e.row.cells[0].innerHTML; fullname = e.row.cells[1].innerHTML; $('#ClientFullName').text(fullname); detailGrid.rebind(); } 

This works with Telerik MVC Extensions , but not with the new version, I get this error:

Unable to get property 'cells' of undefined or null reference. 

I tried to use:

 function onRowSelected(e) { var detailGrid = $('#Visit').data('kendoGrid'); var id = e.row.ClientID; var fullname = e.row.FullName; $('#ClientFullName').text(fullname); detailGrid.rebind(); } 

I get this error:

Unable to get property 'ClientID' of undefined or null reference 

2 Answers 2

2

I found the answer:

 var grid = $("#Clients").data("kendoGrid"); var selectedItem = grid.dataItem(grid.select()); id = selectedItem.ClientID; fullname = selectedItem.FullName; 
Sign up to request clarification or add additional context in comments.

Comments

0

This is due to the fact that the value of 'row' in:

var id = e.row.ClientID; 

is null. So you might want to check if row is null before setting ClientID or cells[0] or cells[1] to the variables. So perhaps:

var id = null; if(e.row != null) id = e.row.ClientId 

However, I think you might need to debug and find out if you're getting any 'row' count at all, though. Because if there is no 'row' then there is no 'row.ClientId' .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.