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

Rad Combo Box in grid problem

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
feras
Top achievements
Rank 1
feras asked on 20 Nov 2008, 12:22 AM
hi,
i am having a rad combobox in the grid edit form template, and i want it to be populated from code behind with linq to sql data source
now i folllowed your example here http://www.telerik.com/support/kb/aspnet-ajax/grid/using-radcombobox-as-editor-in-template-column-of-radgrid.aspx
and added
  protected void Grid_News_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editFormItem = e.Item as GridEditFormItem;

            RadComboBox Combo_Sections = editFormItem.FindControl("Combo_Sections") as RadComboBox;
            var Query_Sections = from s in GetDB().News_society_sections select s;
            Combo_Sections.DataSource = Query_Sections.ToList();
            Combo_Sections.DataTextField = "SectionTitle";
            Combo_Sections.DataValueField = "SectionID";
             
             
        }

but the combo box is empty, also i want the combobox selected item value to be the one in hte DB when the edit form first launch.
thx in advanced.



1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 24 Nov 2008, 01:16 PM
Hi feras,

It seems that you omit to invoke the DataBind() method of the combobox in order to bind it to data inside the ItemDataBound handler of the grid, namely: 

protected void Grid_News_ItemDataBound(object sender, GridItemEventArgs e)  
{  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem editFormItem = e.Item as GridEditFormItem;  
 
            RadComboBox Combo_Sections = editFormItem.FindControl("Combo_Sections"as RadComboBox;  
            var Query_Sections = from s in GetDB().News_society_sections select s;  
            Combo_Sections.DataSource = Query_Sections.ToList();  
            Combo_Sections.DataTextField = "SectionTitle";  
            Combo_Sections.DataValueField = "SectionID";  
            Combo_Sections.DataBind();  
        }  

Additionally, to make the RadComboBox's selected value match that for the corresponding edited item, you need to specify its SelectedValue or SelectedIndex to correspond to the respective value in the grid source. The actual implementation for setting the selected value or index (right after the DataBind() call in the ItemDataBound handler) depends on your custom logic.

Best regards,
Sebastian
the Telerik team

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