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

RadGrid with custom GridDropDownColumn

1 Answer 114 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 10 Feb 2017, 07:16 PM

I have a RadGrid with a customized GridDrownColumn, everything based on this http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/customize-griddropdowncolumn The dropdown is working ok, i've had problems cause in gridViewMode the column was empty, however i manage to handle this.

Now the only problem es when the record is in EditMode, the selected value in the combo is always the first element of the list, no matter wich value is selected

protected void GridSCG_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem) //This is how i show the value in view mode
            {
                GridDataItem item = (GridDataItem)e.Item;
                SCG_DATOS_ADUANA_238 row = (SCG_DATOS_ADUANA_238)e.Item.DataItem;
                item["DTA_TRAFICO"].Text = row.DTA_TRAFICO;
            }
            if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                GridEditManager editMan = editedItem.EditManager;

                GridDropDownListColumnEditor editor = editMan.GetColumnEditor("DTA_TRAFICO") as GridDropDownListColumnEditor;
                editor.DataSource = new DropDownListItem[] { new DropDownListItem("I", "I"), new DropDownListItem("E", "E") };
                editor.DataTextField = "Text";
                editor.DataValueField = "Value";
                editor.DataBind();

                SCG_DATOS_ADUANA_238 row = (SCG_DATOS_ADUANA_238)editedItem.DataItem;
                if (row.DTA_TRAFICO != "")
                {
                    if (row.DTA_TRAFICO == "I")
                        editor.DropDownListControl.SelectedValue = "I";
                    else
                        editor.DropDownListControl.SelectedValue = "E";
                }
                
            }
        }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 15 Feb 2017, 08:43 AM
Hello Victor,

The purpose of the GridDropDownColumn is rather to handle the databinding of the combo/dropdownlist control automatically using the data-related properties like ListDataMember or DataSourceID. If you want to provide the source of combo manually in the code-behind, you can use a GridTemplateColumn instead and bind the control using its DataBinding event handler:
http://www.telerik.com/forums/how-to-have-dropdownlist-and-textbox-inside-a-radgrid#A9aPQyI5vE-ENWi8clmy6Q

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Ajax
Asked by
Victor
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or