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

Databind Combobox in template field

2 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 28 Apr 2008, 09:44 AM
I have a template field on my RadGrid which contains a RadComboBox.  The reason I have the combobox in a template field is so that users can select values without having to go into editmode (i.e. the combox box is in the Item template section not in the edit item template section  for my column)

However I need to be able to programmatically bind the datasource of the combobox in the template column at runtime to a datatable and I can't work out how to do this.

Any help would be appreciated

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 28 Apr 2008, 09:54 AM
Hi,

Try the code in the ItemCreated event below to programatically populate the combobox in the Template column:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
          
        if (e.Item is GridDataItem )  
        {  
            DropDownList drop = (e.Item as GridDataItem) ["TemplateColumn1"].FindControl("DropDownList1") as DropDownList;  
            // dsSet is the DataSet  that is  populated with data from the database 
            drop.DataSource = dsSet;  
            drop.DataTextField = "UserId";  
            drop.DataBind();  
            drop.AutoPostBack = true;  
        }  


Thanks,
Princy

0
Andy
Top achievements
Rank 1
answered on 28 Apr 2008, 10:06 AM
Excellent, thank you very much.  That worked a treat!
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Share this question
or