mercredi 2 novembre 2016

Getting exception StartEdit on DevExpress Grid

I have a patial view with following code(with custom data binding):

Partial View @{

Html.EnableClientValidation();

Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(settings => {
        settings.Name = "GridView1";
        settings.KeyFieldName = "StudentId";
        settings.CallbackRouteValues = new { Controller = "CustomBinding", Action = "MyGridViewPartial" };

        settings.CustomActionRouteValues = new { Controller = "Editing", Action = "ChangeEditModePartial" };

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialAddNew" };

        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialUpdate" };

        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialDelete" };
        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
        settings.SettingsBehavior.ConfirmDelete = true;
        settings.SettingsPopup.EditForm.Width = 600;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowNewButton = true;
        settings.CommandColumn.ShowDeleteButton = true;
        settings.CommandColumn.ShowEditButton = true;


        settings.CustomBindingRouteValuesCollection.Add(
       GridViewOperationType.Paging,
       new { Controller = "MyController", Action = "MyPagingAction" }
   );

        settings.CustomBindingRouteValuesCollection.Add(
        GridViewOperationType.Sorting,
        new { Controller = "MyController", Action = "MySortingAction" }
    );
        settings.SettingsAdaptivity.AdaptivityMode = GridViewAdaptivityMode.Off;
        settings.SettingsAdaptivity.AdaptiveColumnPosition = GridViewAdaptiveColumnPosition.Left;
        settings.SettingsAdaptivity.AdaptiveDetailColumnCount = 1;
        settings.SettingsAdaptivity.AllowOnlyOneAdaptiveDetailExpanded = false;
        settings.SettingsAdaptivity.HideDataCellsAtWindowInnerWidth = 0;


        settings.Columns.Add("StudentId");
        settings.Columns.Add("StudentName");
        settings.Columns.Add("StudentAge");
        settings.Columns.Add("StudentGrade");
        settings.Columns.Add("StudentAddress");

        settings.PreRender = (sender, e) =>
        {

            ((MVCxGridView)sender).StartEdit(0);/**//This is the Exception line**
        };
        settings.CellEditorInitialize = (s, e) =>
        {
            ASPxEdit editor = (ASPxEdit)e.Editor;
            editor.ValidationSettings.Display = Display.Dynamic;

        };
            });
        if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.BindToCustomData(Model).GetHtml()///Custom binding

Please suggest the solutions:

Exception: A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.

Aucun commentaire:

Enregistrer un commentaire