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

Populate RadCombo in Radgrid

7 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vinayak
Top achievements
Rank 1
vinayak asked on 02 Mar 2009, 04:27 AM
Hi,

I am using RadGrid in my asp.net project. When I click on Add new Record link, new row in RadGrid gets added. This new row contains four RadComboBox controls.When I select any particular value in first RadComboBox, respective value should be autopopulated in other three RadComboBox controls of new row. How can I achieve for new row in RadGrid..

Appreciate
if you could help, Thanks!

-Vinayak

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Mar 2009, 10:38 AM
Hellow Vinayak,

I tried the scenario by using FormTemplate with four RadComboBoxes. In the SelectedIndexChanged event of the first RadComboBox, set the selectedvalue of other RadComboBoxes.

Here's the ASPX:
<EditFormSettings EditFormType="Template" >      
<FormTemplate> 
<telerik:RadComboBox ID="RadComboBox1" runat="server"  AutoPostBack="true" 
        onselectedindexchanged="RadComboBox1_SelectedIndexChanged">  
    <Items> 
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" /> 
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" /> 
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" /> 
    </Items> 
</telerik:RadComboBox> 
    <telerik:RadComboBox ID="RadComboBox2" runat="server">  
    <Items> 
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" /> 
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" /> 
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" /> 
    </Items> 
</telerik:RadComboBox> 
    <telerik:RadComboBox ID="RadComboBox3" runat="server">  
    <Items> 
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" /> 
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" /> 
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" /> 
    </Items> 
</telerik:RadComboBox> 
        <telerik:RadComboBox ID="RadComboBox4" runat="server">  
    <Items> 
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" /> 
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" /> 
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" /> 
    </Items> 
</telerik:RadComboBox> 
</FormTemplate> 
</EditFormSettings> 

CS:
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
{  
    RadComboBox combo1 = (RadComboBox)o;  
    String value1= combo1.SelectedValue;  
    //GridEditFormInsertItem item = (GridEditFormItem)combo1.NamingContainer;  
    GridEditFormItem item = (GridEditFormItem)combo1.NamingContainer;  
    RadComboBox combo2 = (RadComboBox) item.FindControl("RadComboBox2");  
    combo2.SelectedValue = combo1.SelectedValue;  //select the second combobox item according to need  
    RadComboBox combo3 = (RadComboBox)item.FindControl("RadComboBox3");  
    combo3.SelectedValue = combo1.SelectedValue; //select the third combobox item  
    RadComboBox combo4 = (RadComboBox)item.FindControl("RadComboBox4");  
    combo4.SelectedValue = combo1.SelectedValue; //select the fourth combobox item  
You can also refer the links which describes about Multiple ComboBoxes

Thanks,
Princy.
0
vinayak
Top achievements
Rank 1
answered on 02 Mar 2009, 11:10 AM
Hi Princy,

Thanks for your reply. I need to use this 4 radcombobox under radgrid. So FormTemplate  will work in this case?
0
Princy
Top achievements
Rank 2
answered on 03 Mar 2009, 08:29 AM
Hello Vinayak,

From your first post, I assumed that the comboboxes were placed in the EditForm of the grid. But from your last post- I suppose you have the comboboxes outside the grid as you have mentioned "I need to use this 4 radcombobox under radgrid". For either of these cases you can populate the RadComboBoxes same logic of setting the selected values of the other three combo boxes when the first combo's selection is changed:
aspx:
<telerik:RadComboBox ID="RadComboBox1" runat="server"  AutoPostBack="true"  
        onselectedindexchanged="RadComboBox1_SelectedIndexChanged">   
    <Items>  
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" />  
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" />  
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" />  
    </Items>  
</telerik:RadComboBox>  
    <telerik:RadComboBox ID="RadComboBox2" runat="server">   
    <Items>  
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" />  
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" />  
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" />  
    </Items>  
</telerik:RadComboBox>  
    <telerik:RadComboBox ID="RadComboBox3" runat="server">   
    <Items>  
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" />  
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" />  
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" />  
    </Items>  
</telerik:RadComboBox>  
        <telerik:RadComboBox ID="RadComboBox4" runat="server">   
    <Items>  
        <telerik:RadComboBoxItem Text="Item1" Value="Value1" />  
        <telerik:RadComboBoxItem Text="Item2" Value="Value2" />  
        <telerik:RadComboBoxItem Text="Item3" Value="Value3" />  
    </Items>  
</telerik:RadComboBox> 

cs:
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)   
{   
    RadComboBox combo1 = (RadComboBox)o;   
    string value1= combo1.SelectedValue;       
    RadComboBox2.SelectedValue = "SelectedValue1";   
    RadComboBox3.SelectedValue = "SelectedValue2"
    RadComboBox4.SelectedValue = "SelectedValue3"
}  

Thanks
Princy.
0
jomy
Top achievements
Rank 1
answered on 29 May 2012, 02:59 PM
My radcombobox in formtemplate in radgrid is not raising the SelectedIndexChangedEvent . despite assigning the event handler to the combobox control in the Grid itemcreated event handler. any help or suggestions.
0
Andrey
Telerik team
answered on 01 Jun 2012, 12:33 PM
Hello,

Could you share your RadGrid declaration along with the code-behind file? Thus everyone that want to help you will have better understanding of your project.

Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
jomy
Top achievements
Rank 1
answered on 01 Jun 2012, 04:59 PM
Hello, this is my code to subscribe to combobox event , combobox which is a part of the edit form template


 

 

protected void grdTestTool_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

 

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)

 

{

 

 

GridEditFormItem editFormItem = e.Item as GridEditFormItem;

 

 

 

RadComboBox automationToolComboBox = editFormItem.FindControl("cmbTestTool") as RadComboBox;

 

 

 

 

 

automationToolComboBox.SelectedIndexChanged += cmbTestTool_SelectedIndexChanged;

 

}

}




But I found the solution, it was my fault of not using the grid's NeedDataSource event to bind the grid.

I used to bind the grid for every postback in the page load, to sustain the grid between postback
with statements :

Radgrid1.Datasource=somelist;
Radgrid1.Databind();

So even an item selection from combobox, which raised the postback used to rebind the grid due to the code in the pageload.
and so my combobox's selectedindexchanged event was not raised.

But I got to know now that handling NeedDataSource Event of grid, would handle postback binding by itself, avoiding the need to bind in the pageload, also NeedDataSource Event would not rebind the grid on selecting the combobox, thus raising the selectedIndexchanged event of combobox.

protected

 

 

void grdTestTool_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

 

{
//Example Code

 

 

List<string> someList = SessionHelper.GetList(Session);

 

 

grdTestTools.DataSource = someList

 

 

}

 

0
Andrey
Telerik team
answered on 05 Jun 2012, 10:07 AM
Hello,

Yes, you are absolutely correct, when FormTemplate is used the simple databinding mechanism is not supported and since you are rebinding the grid on every Page_Load the event information is lost on postback.

More about the NeedDataSource event could be found in this help topic.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
vinayak
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
vinayak
Top achievements
Rank 1
jomy
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or