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

RadGrid - RadComboBox selected value

1 Answer 1285 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 21 Jun 2011, 05:18 PM
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?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jun 2011, 06:13 AM
Hello Richard,

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

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");
           combo.DataSourceID="SqlDataSource1"
           combo.DataTextField="ShipName";
           combo.DataValueField="OrderID";
           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.

Thanks,
Shinu.
Tags
ComboBox
Asked by
Richard
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or