RadGrid - RadComboBox selected value

2 posts, 0 answers
  1. Richard
    Richard avatar
    20 posts
    Member since:
    Sep 2010

    Posted 21 Jun 2011 Link to this post

    I have a RadComboBox embedded on the 'EditFormSettings - FormTemplate' When the user clicks the 'Edit' on the row of information in the data-grid, I would like the RadComboBox to select the existing 'State' that is already selected for the user.  I have text-boxes on the same location and I pre-set the values using:  Text='<%# Bind("strFirstName") %>'  How can I do the same thing for the RadComboBox?

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jun 2011 Link to this post

    Hello Richard,

    You can set the selected value either from aspx or from code behind.
         <telerik:RadComboBox ID="RadCombobox1" runat="server"  AutoPostBack="true" DataSourceID="SqlDataSource1"
    ="ShipName" SelectedValue='<%# Bind("OrderID") %>'>

    If you are populating the combobox from code behind, then try the following.
    Code behind:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
           if (e.Item is GridEditFormItem && e.Item.IsInEditMode)//the grid is about to Edit.
               GridEditFormItem item = (GridEditFormItem)e.Item;
               RadComboBox combo = (RadComboBox)item.FindControl("RadCombobox1");
               TextBox txt=(TextBox)item["OrderID"].Controls[0];
               combo.SelectedValue = txt.Text;

    If you have set LoadOnDemand property to the combobox then try the following approach in the following code library.
    Load On Demand RadComboBox inside an EditItemTemplate of RadGrid.

Back to Top