Current filter:
                                You should refresh the page.
                                Support Center
                                1
                                  • [DX Support team: this thread was cloned from GridView - Сustom databinding issues]

                                    Hello,

                                    I'm trying the new custom binding mode on gridviews and I have several problems implementing it.
                                    I try do display several objects which contain other objects. Here is a simplified example of what my objects looks like :

                                    [C#]
                                    public class Car { public int id; public Engine engine; public string model; public string brand; } public class Engine { public int id; public string brand; public string model; public int horsePower; }

                                    My second problem is when I try to go to the other pages of the gridview. When my controller paging action is called, the StartDataRowIndex of the GridViewPagerState is always 0. Do you have any clue on what could cause this behavior?

                                    Thanks.

                                    Here is my controller code :

                                    [C#]
                                    public class CarController : Controller { [HttpGet, ActionName(CarControllerAction.Car)] public ActionResult Car() { return View(CarControllerAction.Car); } [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post), ActionName(CarControllerAction.Car_Partial)] public PartialViewResult Car_Partial() { var viewModel = GridViewExtension.GetViewModel("gvCar"); if (viewModel == null) { viewModel = new GridViewModel(); viewModel.KeyFieldName = "ID"; viewModel.Columns.Add("ID"); viewModel.Columns.Add("Model"); viewModel.Columns.Add("Brand"); viewModel.Columns.Add("Engine.ID"); viewModel.Columns.Add("Engine.Brand"); viewModel.Columns.Add("Engine.Model"); viewModel.Columns.Add("Engine.HorsePower"); } viewModel.ProcessCustomBinding( MyBindingHandlers.MyGetDataRowCount, MyBindingHandlers.MyGetData); return PartialView(CarControllerAction.Car_Partial, viewModel); } [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post), ActionName(CarControllerAction.Car_Partial_Paging)] public PartialViewResult Car_Partial_Paging(GridViewPagerState pager) { var viewModel = GridViewExtension.GetViewModel("gvCar"); viewModel.Pager.Assign(pager); // pager.PageIndex is always 0 ???!!! viewModel.ProcessCustomBinding( MyBindingHandlers.MyGetDataRowCount, MyBindingHandlers.MyGetData); return PartialView(CarControllerAction.Car_Partial, viewModel); } } public class CarControllerAction { public const string Car = "Car"; public const string Car_Partial = "Car_Partial"; public const string Car_Partial_Paging = "Car_Partial_Paging"; } public static class MyBindingHandlers { static IQueryable<Car> Model { get { return new CarDAO<Car>().GetAll_Query(); } } public static void MyGetDataRowCount(GridViewCustomBindingGetDataRowCountArgs e) { e.DataRowCount = Model.Count(); } public static void MyGetData(GridViewCustomBindingGetDataArgs e) { e.Data = Model .Skip(e.StartDataRowIndex) .Take(e.DataRowCount) .ToList(); } }

                                    And here is my view :

                                    [C#]
                                    @model GridViewModel @Html.DevExpress().GridView( settings => { settings.Name = "gvCar"; settings.CallbackRouteValues = new { Controller = "CarController", Action = CarControllerAction.Car_Partial }; settings.CustomBindingRouteValuesCollection.Add( GridViewOperationType.Paging, new { Controller = "CarController", Action = CarControllerAction.Car_Partial_Paging } ); settings.KeyFieldName = "ID"; settings.Width = System.Web.UI.WebControls.Unit.Percentage(100); settings.Settings.ShowColumnHeaders = true; settings.Settings.ShowFilterRow = true; settings.Settings.ShowFilterRowMenu = true; settings.Settings.ShowFooter = true; settings.Settings.ShowGroupButtons = true; settings.Settings.ShowGroupedColumns = true; settings.Settings.ShowGroupPanel = true; settings.Settings.ShowHeaderFilterButton = true; settings.Settings.ShowTitlePanel = true; settings.Settings.UseFixedTableLayout = true; settings.SettingsBehavior.AllowDragDrop = true; settings.SettingsBehavior.AllowFocusedRow = true; settings.SettingsBehavior.AllowGroup = true; settings.SettingsBehavior.AllowSort = true; settings.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn; settings.SettingsBehavior.ConfirmDelete = true; settings.SettingsBehavior.EnableRowHotTrack = true; settings.SettingsPager.FirstPageButton.Visible = true; settings.SettingsPager.LastPageButton.Visible = true; settings.SettingsPager.PageSize = 50; settings.SettingsPager.PageSizeItemSettings.Visible = true; settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" }; settings.SettingsCookies.Enabled = true; settings.SettingsCookies.CookiesID = settings.Name; settings.SettingsCookies.StoreColumnsVisiblePosition = true; settings.SettingsCookies.StoreColumnsWidth = true; settings.SettingsCookies.StoreFiltering = true; settings.SettingsCookies.StoreGroupingAndSorting = true; settings.SettingsCookies.StorePaging = true; settings.SettingsBehavior.EnableCustomizationWindow = true; settings.SettingsPopup.CustomizationWindow.Height = 500; settings.SettingsPopup.CustomizationWindow.Width = 250; settings.Columns.Add(column => { column.FieldName = "ID"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Model"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Brand"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.ID"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.Brand"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.Model"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.HorsePower"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); } ).BindToCustomData(Model).GetHtml()
                                • Maxim E (DevExpress) 12.07.2012

                                  Hello Kévin,

                                  I have created a sample project according to your description but have not managed to reproduce the issue. See my project in the attachment. Would you please test it and modify to demonstrate the problem? Then send the project to us so that we can examine it on our side under the same conditions.

                                  One of the most probable causes of this problem is that you are using the DefaultModelBinder. The GridView in CustomBinding mode requires using the DevExpressEditorsBinder (this information is added to our answer).

                                  When I was testing the attached MVC Application, I faced another issue. When we change a focused row, the PageIndex is not applied. To get more information about the problem, please refer to the GridView - PageIndex is not applied if a focused row has been changed in Custom Binding mode ticket.

                                  Your patience is greatly appreciated.

                                1 Solution

                                Creation Date Rating Importance Sort by
                                1

                                Kévin,

                                One of the most probable causes of this problem is that you are using the DefaultModelBinder. The GridView in CustomBinding mode requires using the DevExpressEditorsBinder. To learn more about this, please review the Binding of Data Editors article.

                                • Kévin Bariou 12.10.2012

                                  Hello,
                                  It works well with this solution.
                                  Thanks.

                                • Hendra 01.03.2014

                                  Yes. Adding the following code in the "Global.asax.cs" file does the trick:

                                  ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners