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

populating dropdownlist with a default value in dynamically created ItemTemplate

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
taeho
Top achievements
Rank 1
taeho asked on 18 Nov 2008, 08:39 AM
Hi,

There is a section called "Creating ItemTemplate/EditItemTemplate of GridTemplateColumn programmatically" in http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html

What I did was to add the following code inside InstantiateIn function
myDropDownList = new DropDownList();
            myDropDownList.DataSource = myDataSource;
            myDropDownList.DataTextField = "resultLegend";
            myDropDownList.DataValueField = "resultOption";
            myDropDownList.DataBind();
            myDropDownList.Items.FindByValue("C+").Selected = true;

I assigned myDataSource and when I checked myDropDownList.Items, the dropdown list has lists I expected.
But the dropdownlist displays options but the default option is not selected.

Appreciate your help in advance,

Toby

1 Answer, 1 is accepted

Sort by
0
Nikita Gourme
Top achievements
Rank 1
answered on 20 Nov 2008, 04:43 PM
Toby, have you tried to set the selected item/index in the dropdown list hooking the ItemDataBound event of the grid and finding the control in the template column cell? For this purpose you have to set id for the dropdown explicitly when creating it in the InstantiateIn method.

Nikita
Tags
Grid
Asked by
taeho
Top achievements
Rank 1
Answers by
Nikita Gourme
Top achievements
Rank 1
Share this question
or