This is a migrated thread and some comments may be shown as answers.

[Solved] RowAction, Ajax and OnRowSelected problem

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vit
Top achievements
Rank 1
Vit asked on 10 Mar 2011, 05:39 PM
I am using Q1 beta, but not sure if problem exists in previous release.

This is part of my view:
    <%  Html.Telerik().Grid<ItemsModel>()
           .Name("Grid")
           .RowAction(row =>
               {
                   if (row.DataItem.ItemName== "Item1")
                       {
                               row.HtmlAttributes["style"] = "background:green;";
                       }
               })
           .DataKeys(keys => keys.Add(k => k.ItemId))
           .DataBinding(dataBinding =>
               dataBinding.Ajax()
               .Select("Items", "Items")
               .Columns(columns =>
               {
                   columns.Bound(c => c.ItemId).Hidden(true);
                   columns.Bound(c => c.ItemName).Width(90);
               })
           .Pageable()
           .Selectable()
           .ClientEvents(events => events.OnRowSelected("onRowSelected"))
           .Render();
  
        Html.Telerik().ScriptRegistrar()
            .Scripts(scripts =>
                scripts.AddGroup("CommonScript", group =>
                    group.Add("telerik.window.min.js")
                         .Add("telerik.draganddrop.min.js")))
            .OnDocumentReady(@"
function onRowSelected(e) {
   var id = e.row.cells[0].innerHTML;
   detailsWindow = $.telerik.window.create({
     name: 'detailsWindow', title: 'Items', modal: true, draggable: true, contentUrl: '/Items/Item/' + id,
     onClose: function (e) { e.preventDefault(); detailsWindow.data('tWindow').destroy(); }
   });
   detailsWindow.data('tWindow').center().open();
}");
    %>
It gives me this error on render at line 13:
Server Error in '/' Application.
  
Object reference not set to an instance of an object.
  
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  
Source Error: 
  
  
Line 11:            .RowAction(row =>
Line 12:                {
Line 13:                    if (row.DataItem.ItemName == "Item1")
Line 14:                    {
Line 15:                        row.HtmlAttributes["style"] = "background:green;";

If I change RowAction to this:
.RowAction(row =>
    {
            row.HtmlAttributes["style"] = "background:green;";
    })
then there is no error, but it makes background green for a split second while grid is rendering. After that - just regular colors from row selection.

Am I doing something wrong or RowAction does not work with OnRowSelect with Ajax binding?

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Mar 2011, 12:54 PM
Hello Vit,

Unfortunately, I'm unable to recreate the error you have described. Could you please verify that the DataItem is not null.
If you continue to experiencing difficulties please provide a small runnable project in which the issue can be observed.

Regards,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Vit
Top achievements
Rank 1
answered on 14 Mar 2011, 02:37 PM
I have created and attached sample project.
0
Rosen
Telerik team
answered on 14 Mar 2011, 05:15 PM
Hi Vit,

Thank you for sending us the project. I was able to observed the error you have described. However, we have already addressed this issue and the fix will be available in the official Q1 2011 release.

Best wishes,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Vit
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Vit
Top achievements
Rank 1
Share this question
or