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

Combo box in inside EditFormSetting FormTemplate

6 Answers 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Serban
Top achievements
Rank 1
Serban asked on 02 Nov 2010, 06:08 AM
Can you have a Combobox inside:

<EditFormSettings EditFormType="Template">
                    <FormTemplate>
??? combo bound to datafield from grid????
      </FormTemplate>
</EditFormSettings>

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Nov 2010, 06:53 AM
Hello Serban,

Yes, It is possible to have any control inside FormTemplate. Here is one sample code which places RadComboBox in FormTemplate section and populating it with SqlDataSource. You can also populate it with any DataSource by accessing it from code behind.

C#:
<FormTemplate>
   <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource1" DataTextField="FirstName" DataValueField="FirstName" >
   </telerik:RadComboBox>
</FormTemplate>

Also please go through the following demo for more information on FormTemplate.
Grid / Form Template Edit Form.

Thanks,
Princy.
0
Serban
Top achievements
Rank 1
answered on 02 Nov 2010, 09:30 PM
Thankyou Princy.

Not sure how this would work with Entity Framework as the data source ID would not be filled.

I may be able to just use:  DataTextField="FirstName" DataValueField="FirstName"

Any thoughts on using a telerik:RadComboBox with EF datasource inside a FormTemplate?
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Nov 2010, 12:32 PM
Hello Serban,
 You can achieve this by accessing the RadComboBox inside FormTemplate from code behind and set its DatSource property from there. Sample code is given below. 

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem  && e.Item.IsInEditMode)//editform
       {
         GridEditFormItem editItem = (GridEditFormItem)e.Item;
         RadComboBox rdcombo = (RadComboBox)editItem.FindControl("RadComboBox2");
         rdcombo.DataSource=//Set your datasource here.
         rdcombo.DataTextField=//set the DataTextField
         rdcombo.DataValueField=//set the DataValueField
         rdcombo.DataBind();
       }
    }

Thanks,
Princy.
0
Serban
Top achievements
Rank 1
answered on 03 Nov 2010, 09:30 PM
Amazing! Thankyou!
0
Sarada
Top achievements
Rank 1
answered on 02 May 2014, 07:23 PM

It is working fine. But my question how do we bind to a field in the radgrid
from code behind
protected void RadGrid_SC_D_ItemDataBound(object sender, GridItemEventArgs e)
{

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)//editform
{

GridEditFormItem editItem = (GridEditFormItem)e.Item;

RadComboBox rdcombo = (RadComboBox)editItem.FindControl("RadComboBoxSpClass");
DataTable mdSpClass = Database.Load("SELECT [spon_class_id], [spon_class_name] FROM [grant_code_spon_class] WHERE spon_class_ser='" + DDL_SLS_D.SelectedItem.Text.Trim() + "'", "spclass");
rdcombo.DataSource = mdSpClass;
rdcombo.DataTextField ="spon_class_name";
rdcombo.DataValueField = "spon_class_id";
rdcombo.DataBind();

}

}
From the above code, when I click a row for edit in RadGrid, my ComboBox was showing exacltly what I wanted to see. But it is not bound to a field in the radgrid.
From the below code, you could see that with a RadCombobox when the datasource is specified in the control, I am able to bind the field in the telerik RagGrid. But how do I acheive that with Telerik ComboBox, where my datasource I have done with code behind. I had to comment that one to see atleast it is working
<telerik:RadComboBox runat="server" ID="RadComboBoxSpClass" DataTextField="spon_class_name" Height="300"
DataValueField="spon_class_id" DataSourceID="SPClassDataSource" SelectedValue='<%#Bind("dmn_spons_class_id") %>' Width="250">
</telerik:RadComboBox>
 <asp:SqlDataSource ID="SPClassDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:strCnnNovaDev %>"
SelectCommand="SELECT [spon_class_id], [spon_class_name] FROM [grant_code_spon_class] ">
</asp:SqlDataSource>
<%--<telerik:RadComboBox runat="server" ID="RadComboBoxSpClass" AutoPostBack="true" Width="250" Height="300" >
</telerik:RadComboBox>--%> 
0
Princy
Top achievements
Rank 2
answered on 05 May 2014, 06:00 AM
Hi Sarada,

I guess you want to bind your RadComboBox in view mode from code behind. Please try the following code snippet:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
    {
         GridDataItem dataItem = (GridDataItem)e.Item;
         RadComboBox radcombo = (RadComboBox)dataItem.FindControl("RadComboBoxSpClass");      
         radcombo.DataSourceID="SPClassDataSource";
         radcombo.DataTextField="spon_class_name";
         radcombo.DataValueField="spon_class_id";
         radcombo.SelectedValue = DataBinder.Eval(dataItem.DataItem, "spon_class_id").ToString();      
       }
    }

Thanks,
Princy
Tags
Grid
Asked by
Serban
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Serban
Top achievements
Rank 1
Sarada
Top achievements
Rank 1
Share this question
or