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

Binding field to RadComboBox in FormTemplate

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 22 Feb 2012, 09:45 PM
Hi,

I have simple RadComBox inside my form template. I fill this ComboBox inside the RadGrid_ItemCreated.

I set a value and a text for each RadComboBoxItem. I can't find a DataField Property for ComboBox to select automatically the right item from the DataSource. Is there a way to achieve this? Or I'll need to loop inside ComboBox to select the right one?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 May 2012, 08:07 AM
Hi Jocelyn,

I guess you want to show the SelectedValue of ComboBox in FormTemplate.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem eitem = (GridEditFormItem)e.Item;
        RadComboBox RadComboBox1= (RadComboBox)eitem.FindControl("RadComboBox1");
        RadComboBox1.DataSourceID = "SqlDataSource1";
        RadComboBox1.DataTextField = "OrderID";
        RadComboBox1.DataValueField = "OrderID";
        RadComboBox1.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "OrderID").ToString();
    }
}

Please provide the code if it doesn't help.

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