2

I have a RadGrid which has in place insert and edit functionality.

One of the fields is a drop down.

My requirements are

  • When the user clicks "Add New" I want to be able to change some of the properties on the dropdown and populate it when data
  • When the user edits a row I need to change the selected index of the drop down to show the data being edited and disable it. I somehow need to handle one of the grids events, determine if its in insert/edit mode and then use FindControl to get access to my drop down.

Ive looked at a number of events such as ItemCommand, DataBound, ItemCreated etc and I just cant figure out how to get access to my drop down? I need to know what object I need to call find control on to get to my drop down.

Thanks.

Devjosh
  • 6,450
  • 4
  • 39
  • 61
Remotec
  • 10,304
  • 25
  • 105
  • 147

2 Answers2

1

You may try to use GridDropDownColumn to create a drop down column inside grid which auto populates drop down in edit or insert mode. Example:

<telerik:GridDropDownColumn UniqueName="ParamType" DataField="ParamType" HeaderText="Parameter type" HeaderStyle-HorizontalAlign="Center" DropDownControlType="RadComboBox" ListDataMember="ParamType" ListTextField="ParamType" ListValueField="ParamType">
</telerik:GridDropDownColumn>

And you can populate data or access to drop down box inside ItemDataBound event. Example:

    protected void GvParametersItemDataBound(object sender, GridItemEventArgs e)
    {
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    //bind data to ddl in edit mode
                    GridEditableItem editedItem = e.Item as GridEditableItem;
                    GridEditManager editMan = editedItem.EditManager;
                    GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("DropDownColumnUniqueName"));
                    RadComboBox ddList = editor.ComboBoxControl;
                    ddList.RenderMode = Telerik.Web.UI.RenderMode.Auto;

                    ddList.OnClientSelectedIndexChanged = "OnClientSelectedParamerterIndexChanged";
                    ddList.DataTextField = Constants.DataTextField;
                    ddList.DataValueField = Constants.DataValueField;
                    ddList.DataSource = GetParameterTypes();
                    ddList.DataBind();
                }
    }
Diane
  • 51
  • 6
1

Start from this doc and bear in mind that to determine the insert/update operation, you can check the GridTableView.IsItemInserted property and the EditItems collection of the grid respectively. The appropriate events to change item values or disable the dropdown are ItemDataBound and ItemCreated.

Dick Lampard
  • 2,256
  • 1
  • 12
  • 7