drop down list in a grid

2 posts, 0 answers
  1. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 19 Oct 2008 Link to this post

    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;  
     
                      
                }  
            } 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Oct 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top