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

drop down list in a grid

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 19 Oct 2008, 02:28 PM
I have a grid that uses a RADCombo for selection values in a row.  When I select 'Edit' Ive put some code in the ItemCreated event that populates the dropdown from a custom object.  This all works fine except that the dropdown list always shows the first item in the list.  I need to pre-select the value in the dropdown that matches the value in the grid

eg  in the grid column I have "80's"

the drop down has 2 values  "70's"  and "80's" and it always shows "70's" as the value when in fact is should be "80's"

How can I get the value from the cell to pre-select the value ?

Heres how im getting the drop down
protected void RadGridSecondaryCategories_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
                  
           
 
 
                GridEditableItem _item = (GridEditableItem)e.Item;  
                  
 
                Telerik.Web.UI.RadComboBox cb = (Telerik.Web.UI.RadComboBox)_item["Category"].FindControl("RadComboBoxCategories");  
                cb.DataSource = categorymanager.Categories(this.RadComboBoxArtistGenre.SelectedValue, this.RadComboBoxType.SelectedValue);  
                cb.DataTextField = "Category";  
                cb.DataValueField = "Category";  
                cb.DataBind();  
                  
 
                //TO DO:  
                //put code here to find the item in the dropdown from the database  
 
                TableCell cell = _item["Category"];  
                  
 
                int index = this.RadComboBoxCategories.FindItemIndexByValue();--- need to get the cell value and put it here  
                cb.SelectedIndex = index;  
 
                  
            }  
        } 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Oct 2008, 03:56 AM
Hello Mark,

You can try out the following code select values in the dropdown that matches the grid value.
cs:
 
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem dataitem = (GridEditableItem)e.Item;  
            RadComboBox cb = (RadComboBox)dataietm["Category"].FindControl("RadComboBoxCategories");   
                cb.DataSource = categorymanager.Categories(this.RadComboBoxArtistGenre.SelectedValue, this.RadComboBoxType.SelectedValue);   
                cb.DataTextField = "Category";   
                cb.DataValueField = "Category";   
                cb.SelectedIndex = e.Item.ItemIndex;  
                cb.DataBind();             
             
        }  

Thanks
Princy.
Tags
Grid
Asked by
mww
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or