Bug Report B230988
Visible to All Users

GridView does not show columns for complex fields in Custom Binding mode

created 12 years ago (modified 12 years ago)

[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 first problem is that I am unable to display Engine properties in the gridview using custom databinding. In the method linked to the gridview's settings.CallbackRouteValues property, I use the GridViewExtension.GetViewModel method to get the gridview's viewmodel. When it is null, I create a new viewmodel and add the same columns that my gridview contains. Then I bind the viewmodel to my data using the ProcessCustomBinding method. My data is a List<Car>. It works well for Car simple attributes (id, model, brand). However I am not able to display Engine properties. When I use Linq databinding to display the engine's horsePower, all I have to do is to set the gridview's column fieldname to "Engine.horsePower" This method doesn't seem to work with this binding method. Do I have to manually feed each of the viewmodel field to achieve this? 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()

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello Kévin,
I have reproduced this issue on our side.The problem is specific for GridView in CustomBinding mode.Our developers will do their best to fix this problem as soon as they can.

    Show previous comments (4)
    DevExpress Support Team 12 years ago

      Hello Troy,
      The Public Fix is not available any more since we plan to release the next version v12.2.5 soon. This bug fix will be included there. When we release the new version, you can upgrade your project to get this and other bug fixes.

      P P
      Pablo Andrés Restrepo Urango 8 years ago

        Hi Group DevExpress.

        I'm tring this solution but don't run correctly, muy version is 15.1

        i have that code on my solucion, the only diference is that i'm getting date from my DB with store procedure this sp return only tow columns and that is my binding.

        DevExpress Support Team 8 years ago

          Hello Pablo,

          This ticket is dedicated to a bug fix, so the solution for this thread is added to our code base (including v15.1) and does not require additional coding. So, it is not quite clear which code you have used in your application. I suggest that you refer to the GridView - Сustom databinding questions ticket created on your behalf for further assistance on your particular case.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.