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

Add GridDropDownColumn at runtime

1 Answer 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 09 Dec 2008, 09:31 AM
Hello everyone,

Right now I need to add a GridDropDownColumn at runtime, not design time, and the dropdowmitem's data come from a Dictionary, the key is the item's value, the value is the item's text. How can I do it?

Part of my code looks like :

        Dictionary<stringstring> dicValues = DropdownListData as Dictionary<stringstring>;  
        if (dicValues != null)  
        {  
            GridDropDownListColumnEditor editor = gridColumn.ColumnEditor as GridDropDownListColumnEditor;  
            foreach (KeyValuePair<stringstring> value in dicValues)  
            {  
                editor.DropDownListControl.Items.Add(new ListItem(value.Value, value.Key));  
            }  
        } 

But I got nothing, when I switch to the edit model, the dropdownlist has no items. Any one know how to do this?

Thanks and Best regards,

Bryan.

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 11 Dec 2008, 02:33 PM
Hello Bryan,

The built-in GridDropDownColumn is designed to be used mainly with DataTables in order to easily map and generate their dropdown items values in conjunction with the DataField/ListValueField/DataSourceID/ListDataMember values of the column.

For custom objects collections consider replacing the GridDropDownColumn with template column holding MS DropDownList in its edit template (generating/binding the items for the MS DropDownList inside the ItemDataBound handler of RadGrid). Review this topics from the documentation which elaborates on the same subject:

http://www.telerik.com/help/aspnet-ajax/grdoperationswithdropdownlistinedititemtemplate.html

How to generate columns in the grid programmatically you can see from this article.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Bryan
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or