We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to set DropDownDataSource when using GridPropertiesModel?

Hi All,

Is anyone able to provide a sample of a Grid with a column that has a CellEditType of DropdownEdit and is bound to a data source using DropDownDataSource but using the GridPropertiesModel?

I construct my GridPropertiesModel like this, I can see that the data source for the column is correctly populated in the view, (List of strings) but the dropdown is still empty...

 GridPropertiesModel<DataRow> model = new GridPropertiesModel<DataRow>()
            {
                ActionMode = ActionMode.JSON,
                DataSource = m_API.execQuery("select * from TEST").AsEnumerable()
            };

            GridEditing edit = new GridEditing()
            {
                AllowNew = true,
                EditMode = GridEditMode.Normal,
                AllowEdit = true,
                AllowDelete = true,
                PrimaryKey = new List<string> { "ID" }
            };

model.Columns = new List<GridColumn<DataRow>>
            {
                new GridColumn<DataRow>
                {
                    HeaderText = "Column A",
                    MappingName = "ID"
                },
                new GridColumn<DataRow>
                {
                    HeaderText = "Column B",
                    MappingName = "COLUMN1",
                    CellEditType = CellEditType.DropdownEdit
                },
                new GridColumn<DataRow>
                {
                    HeaderText = "Column C",
                    MappingName = "TYTY1",
                    CellEditType = CellEditType.DropdownEdit,
                    DropDownDataSource = new List<string> { "AAA", "BBB", "CCC", }
                },
            };

Much appreciated, Laz


2 Replies

LB Laszlo Boross April 10, 2014 02:29 AM UTC

I have isolated the issue to the fact that I am binding to a DataTable/DataRow instead of an EF Entity...

If I change my Grid to bind to the entity 'INSTANCE', the dropdown populates as expected...

public ActionResult GridEdit6(int id)
        {
            IEnumerable data = m_DS.INSTANCES.ToList();

            GridPropertiesModel<INSTANCE> model = new GridPropertiesModel<INSTANCE>()
            {
                ActionMode = ActionMode.JSON,
                DataSource = data
            };

            GridEditing edit = new GridEditing()
            {
                AllowNew = true,
                EditMode = GridEditMode.Normal,
                AllowEdit = true,
                AllowDelete = true,
                PrimaryKey = new List<string> { "ID" },
            };

            model.Editing = edit;

            model.Columns = new List<GridColumn<INSTANCE>>
            {
                new GridColumn<INSTANCE>
                {
                    HeaderText = "Column A",
                    MappingName = "ID"
                },
                new GridColumn<INSTANCE>
                {
                    HeaderText = "Column B",
                    MappingName = "DB_VERSION",
                    CellEditType = CellEditType.DropdownEdit
                },
                new GridColumn<INSTANCE>
                {
                    HeaderText = "Column C",
                    MappingName = "PDB",
                    CellEditType = CellEditType.DropdownEdit,
                    DropDownDataSource = (Array)new string[] { "AAA", "BBB", "CCC", "DDD", }
                }
            };

            ViewData["GridModel"] = model;

            return View();

        }


My View is defined as below:


@model Essatto5.API.INSTANCE
@{
    ViewBag.Title = "Home Page";
}

<br />

<div>
    @( Html.Syncfusion().Grid<Essatto5.API.INSTANCE>("ViewGrid6", (GridPropertiesModel<Essatto5.API.INSTANCE>)ViewData["GridModel"]))
</div>


Any assistance is appreciated, Laz



AS Alan Sangeeth S Syncfusion Team April 11, 2014 11:00 AM UTC

Hi Laszlo,

We are able to reproduce the issue “In DataTable, DropDown is empty while editing ”, to get a solution for this behavior, please contact us at Syncfusion Support or you may also open a support ticket by login in to direct trac account and mention this forum link for reference.

Regards,

Alan Sangeeth S


Loader.
Live Chat Icon For mobile
Up arrow icon