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

Issues when binding OnEdit to a handler

2 Answers 39 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.
Rajesh
Top achievements
Rank 1
Rajesh asked on 09 Apr 2012, 08:29 AM
Hi,

I have a grid with inline editing enabled. It works fine when no OnEdit handler is specified (i.e. it displays data properly, and i am able to add new rows to the Grid). However, once i attach an OnEdit handler, even if the handler is empty -

1. the grid does not display any data
2. when trying to insert a new row, i get a runtime exception (ArgumentException)

System.ArgumentException occurred
  Message=An item with the same key has already been added.
  Source=mscorlib
  StackTrace:
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at System.Web.Mvc.ViewDataDictionary.Add(String key, Object value)
       at Telerik.Web.Mvc.UI.GridForeignKeyColumn`2.AppendSelectList(IDictionary`2 viewData, Object dataItem)
       at Telerik.Web.Mvc.UI.Html.GridForeignKeyEditorForCellBuilder`2.AppendCellContent(IHtmlNode td, Object dataItem)
       at Telerik.Web.Mvc.UI.Html.GridDataCellBuilderBase.CreateCell(Object dataItem)
       at Telerik.Web.Mvc.UI.Html.GridInLineEditRowBuilder.AppendEditor(IHtmlNode container)
       at Telerik.Web.Mvc.UI.Html.GridInLineEditRowBuilder.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow()
       at Telerik.Web.Mvc.UI.Html.GridDataSectionBuilder.CreateBody(IEnumerable`1 rowBuilders)
       at Telerik.Web.Mvc.UI.Html.GridDataSectionBuilder.CreateBody(GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Html.GridHtmlBuilder.CreateBody(GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Html.GridScrollingHtmlBuilder.CreateContentTable(GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Html.GridScrollingHtmlBuilder.CreateContent(GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Html.GridScrollingHtmlBuilder.AppendData(IHtmlNode div, GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Html.GridHtmlBuilder.CreateGrid(IDictionary`2 htmlAttributes, GridFunctionalData functionalData, GridRenderingData renderingData)
       at Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer)
       at Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString()
       at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString()
       at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToString()
       at System.Web.HttpWriter.Write(Object obj)
       at System.Web.Mvc.ViewPage.SwitchWriter.Write(Object value)
       at System.Web.UI.HtmlTextWriter.Write(Object value)
       at ASP.areas_scenariomanagement_views_scenario_maturitydefaulttimingconditions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\Fin_user3\Documents\Visual Studio 2010\Projects\dirty2\CmbsAdvisor\CmbsAdvisor.Web\Areas\ScenarioManagement\Views\Scenario\MaturityDefaultTimingConditions.ascx:line 19
  InnerException: 


Note that i have multiple foreign key columns in the grid, all bound using the ForiegnKey method. 

<% = Html.Telerik().Grid<MaturityDefaultCondition>()
        .Name("MaturityDefaultConditionGrid")
        .HtmlAttributes(new { style = "width: 100%"})
        .Footer(false)
        .DataKeys(keys =>
        {
            keys.Add(mdc => mdc.Id);
        })
        .ToolBar(commands =>
        {
            commands.Insert().ButtonType(GridButtonType.BareImage).ImageHtmlAttributes(Url.Content("~/Content/Images/AddSmall.png"));
            //commands.SubmitChanges();
            commands.Position(GridToolBarPosition.Bottom);
             
        })
        .DataBinding(dataBinding =>
            dataBinding.Ajax()
                .Select("_GetMaturityDefaultConditions", "Scenario")
                .Update("_SaveMaturityDefaultConditions", "Scenario")
        )
        .Columns(columns =>
        {
            columns.Bound(mdc => mdc.DebtYield_GT).Title("Debt Yield>");
            columns.Bound(mdc => mdc.DebtYield_LTE2).Title("Debt Yield<=");
            columns.ForeignKey(mdc => mdc.SSId, (IEnumerable)ViewData["ssDetailsList"],
                   "Id", "SSName").Title("SS");
            columns.Bound(mdc => mdc.OccupancyPct).Title("Occupancy% >=");
            columns.Bound(mdc => mdc.OccupanyExpires).Title("Expiration>=(months)");
            columns.ForeignKey(mdc => mdc.AndOrLSBetw, (IEnumerable)ViewData["MDCAndOrLSBetwList"], "Id", "Text").Title("And/Or");
            columns.Bound(mdc => mdc.LossSeverityGTE).Title("Loss Severity% >=");
            columns.Bound(mdc => mdc.LossSeverityLT).Title("Loss Severity% <");
            columns.ForeignKey(mdc => mdc.MaturityAction, (IEnumerable)ViewData["MaturityActionTypeList"], "Id", "ActionType").Title("Action");
            columns.Bound(mdc => mdc.ExtendByMonths).Title("Extend By(months)");
            columns.Bound(mdc => mdc.PaydownPct).Title("Paydown %");
            columns.Command(commands => commands.Delete().ImageHtmlAttributes("img src='" + Url.Content("~/Content/Images/DeleteRed.png") + "'").ButtonType(GridButtonType.BareImage)).Width(40).Title("");
        })
        .ClientEvents(events =>
            events//.OnDataBinding("MaturityDefaultConditionGrid_onDataBinding")
                    //.OnError("MaturityDefaultConditionGrid_onError")
                    //.OnLoad("MaturityDefaultConditionGrid_onLoad")
                    //.OnRowDataBound("MaturityDefaultConditionGrid_onRowDataBound")
                    .OnComplete("MaturityDefaultConditionGrid_onComplete")
                    .OnEdit("MaturityDefaultConditionsGrid_onEdit") //--- WORKS FINE IF I COMMENT THIS OUT
         )
        .Editable(editing => editing.Mode(GridEditMode.InCell))
        .Editable(editing => editing.DefaultDataItem(new MaturityDefaultCondition {AndOrLSBetw=1, LossSeverityGTE=0, LossSeverityLT=100, MaturityAction=1}))
        .Scrollable(sc =>
            {
                sc.Height(160);
            })
        .KeyboardNavigation(knb =>
            {
                knb.EditOnTab(true);
            }
        )
%>
The OnEditHandler currently is

function MaturityDefaultConditionsGrid_onEdit(e) {
       debugger;
       var row = e.row;
       // $("#MaturityAction").bind('change', function () {
           alert("Bound");
       //});
       //or better : $(row).find('.t-dropdown').addClass('myClass');
   }


Any insights will be appreciated.

2 Answers, 1 is accepted

Sort by
0
Rajesh
Top achievements
Rank 1
answered on 09 Apr 2012, 04:01 PM
I may have found the solution. I was adding the forign keys to the keys collection. Once i removed the same, things are working fine. However, not sure why the same code workd when OnEdit handler is not specified.
0
Samantha
Top achievements
Rank 1
answered on 30 May 2012, 08:49 AM
I have the same issue. Whenever i use the OnEdit event my grid wont load any data in it
Tags
Grid
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Rajesh
Top achievements
Rank 1
Samantha
Top achievements
Rank 1
Share this question
or