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

Insert in hierarchical grid

3 Answers 94 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.
Christian
Top achievements
Rank 1
Christian asked on 02 Sep 2010, 05:10 PM
Hi

Is inserting supported for the master in a hierarchical grid?

when I add the insert button in the toolbar and click it, I get a null pointer exception

Html.Telerik().Grid(Model)
       .Name("GroupGrid")
       .DataKeys(k => k.Add(g => g.GroupID))
       .Columns(columns =>
       {
           columns.Bound(g => g.GroupID).ReadOnly().Width(100);
           columns.Bound(g => g.GroupName).Width(100);
       })
       .ToolBar(tb => tb.Insert())
       .DetailView(groupDetailView => groupDetailView.Template(g =>
       {
           %>
               <%=
               Html.Telerik().Grid(g.Roles)
                   .Name("GroupGrid_RoleDetails_" + g.GroupID)
                   .Columns(columns =>
                                {
                                    columns.Bound(r => r.RoleID).Width(100);
                                    columns.Bound(r => r.RoleName).Width(200);
                                })
                   .Pageable()
                   .Sortable()                
               %>
           <%
       }))
       .DataBinding(db => db.Server().Insert("AddGroup", "Group"))
       .Pageable(pager => pager.PageSize(20))
       .Sortable()
       .Selectable()
       .Filterable()
       .Render();

It displays the grid for Groups including the child grid for Roles, but when clicking on "Add new record" I get

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.Mvc.UI.Html.GridEditRowHtmlBuilder`1.CreateTable() +541
   Telerik.Web.Mvc.UI.Html.GridEditRowHtmlBuilder`1.BuildCore() +130
   Telerik.Web.Mvc.UI.HtmlBuilderBase.Build() +72
   Telerik.Web.Mvc.UI.GridHtmlBuilder`1.CreateRow(GridRow`1 row) +119
   Telerik.Web.Mvc.UI.GridHtmlBuilder`1.AppendRows(IHtmlNode body, IEnumerable`1 dataSource) +362
   Telerik.Web.Mvc.UI.GridHtmlBuilder`1.CreateBody() +572
   Telerik.Web.Mvc.UI.GridHtmlBuilder`1.BuildCore() +594
   Telerik.Web.Mvc.UI.HtmlBuilderBase.Build() +72
   Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +1135
   Telerik.Web.Mvc.UI.ViewComponentBase.Render() +148
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() +55
   ASP.views_group_editgroups_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in ...\Views\Group\EditGroups.aspx:13
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in ...\Views\Shared\Site.Master:42
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

When I try to include the insert functionality in your examples HierarchyServerSide or DetailsServerSide I get also NullReferenceException

3 Answers, 1 is accepted

Sort by
0
Jigar
Top achievements
Rank 1
answered on 02 Sep 2010, 06:52 PM
Hi Fabiano,

Yes it works, try to use <#= groupId #> in detail grid, ex. .Name("GroupGrid_RoleDetails_" + <#= GroupID #>).

I tried it with ajax and it works well.

Regards,

Jigar.


0
Christian
Top achievements
Rank 1
answered on 03 Sep 2010, 08:56 AM
Hi Jigar

Thanks for your reply.

Unfortunately this doesn't help. I am using the serverbinding scenario and I think your solution is only for client side binding
0
Accepted
Atanas Korchev
Telerik team
answered on 03 Sep 2010, 10:25 AM
Hi Fabiano,

I am afraid you have discovered a bug. The workaround would be to use Ajax editing and binding if that's an option. If not - you can apply the fix easily by editing GridEditRowHtmlBuilder.cs from the source distribution:

  1. Locate this code:
     var detailViewAdorner = new GridToggleDetailViewAdorner
     {
             Expanded = Row.DetailRow.Expanded
     };
  2. Change it to:
     var detailViewAdorner = new GridToggleDetailViewAdorner
     {
             Expanded = Row.DetailRow != null ? Row.DetailRow.Expanded : false
     };
  3. Then rebuild and use the output assembly in your project


There is one more thing that needs to be taken into consideration. Currently you need a commands column with an Edit command present in order to display the "insert" and "cancel" buttons.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Jigar
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or