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

GridDropDownColumn

1 Answer 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kim
Top achievements
Rank 1
Kim asked on 28 Oct 2013, 03:38 AM
Hi, I am having trouble implementing a simple GridDropDownColumn

<telerik:GridDropDownColumn UniqueName="OrderStatusID" DataField="OrderStatus" ListValueField="Description" ListTextField="ID" Headertext="Order Status" ></telerik:GridDropDownColumn>

First, OrderStatus is not showing in the grid, second, how to I populate the drop down list in code behind? The list contains a list of Items with properties ID and Description


Thanks.





1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 30 Oct 2013, 02:11 PM
Hello Kim,

In order to display the OrderStatus in scenarios where a DataSourceID is not defined you should set it as a ListDataMember:

ASPX:
<telerik:GridDropDownColumn UniqueName="OrderStatusID" DataField="OrderStatus" ListDataMember="OrderStatus" ListValueField="Description" ListTextField="ID" Headertext="Order Status" ></telerik:GridDropDownColumn>

As for dynamically populating the drop down this is achievable by following the below listed steps:
  1. Subscribe to the OnItemDataBound event of the grid.
  2. Obtain a reference to RadComboBox in the edit item.
  3. Assign a data source to it and call .DataBind.

For obtaining a reference to the drop down you can use this code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       GridEditableItem editItem = e.Item as GridEditableItem;
       if (editItem != null && editItem.IsInEditMode)
       {
           RadComboBox editItemCombo = editItem["OrderStatusID"].Controls[0] as RadComboBox;
           //Implement data binding logic
       }
   }

Regards,
Angel Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Kim
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or