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

RadComboBox in RadGrid - cannot get selectedindexchanged event

3 Answers 314 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mala
Top achievements
Rank 1
Mala asked on 15 Jan 2010, 08:37 PM
Hi,

I have a RadGrid and a RadComboBox as a column of the grid. When user selects a value in the combobox I need to enable/disable some cells on the same row. Hence I need the selectedindexchanged event to fire.
I referred the example on the telerik website and based on that I coded this functionality. However, the selectedindexchanged event does not fire. The code snippet is below.
Thanks, Mala

Here is my code snippet:
UAMain02.aspx

<

 

telerik:GridTemplateColumn AllowFiltering="false" SortExpression="OccCode" HeaderText="Occ Code *" UniqueName="OccCode">

 

 

 

 

<HeaderStyle Width="70px" />

 

 

 

 

<ItemStyle Width="70px" />

 

 

 

 

<ItemTemplate>

 

 

 

 

<telerik:RadComboBox ID="radComboBoxOccCode" runat="server" Autopostback="true" Width="50px" >

 

 

 

 

</telerik:RadComboBox>

 

 

 

 

<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidatorOcc" runat="server" ControlToValidate="radComboBoxOccCode" ErrorMessage="*" ValidationGroup="vgFirst"></asp:RequiredFieldValidator>

 

 

 

 

</ItemTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 



and the code behind is:
UAMain02.aspx.cs

 

private void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

}

 

 

 

protected void radGrOccupation_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

 

 

if (e.Item is GridDataItem)

 

{

 

 

 

GridDataItem insertItem = (GridDataItem)e.Item;

 

 

 

 

RadComboBox combo = (RadComboBox)insertItem["OccCode"].FindControl("radComboBoxOccCode");

 

 

combo.AutoPostBack =

 

 

true;

 

combo.SelectedIndexChanged +=

 

 

new RadComboBoxSelectedIndexChangedEventHandler(this.combo_SelectedIndexChanged);

 

 

 


3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 18 Jan 2010, 08:26 AM
Hello Mala,

I would suggest you to attach the event handler of the RadComboBox on the ItemCreated event instead on the ItemDataBound one:

protected void radGrOccupation_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
        {
            GridDataItem insertItem = (GridDataItem)e.Item;
            RadComboBox combo = (RadComboBox)insertItem["OccCode"].FindControl("radComboBoxOccCode");
            combo.AutoPostBack = true;
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(this.combo_SelectedIndexChanged);
        }
}

For more information about the difference between ItemDataBound and ItemCreated events review the following help article:

Distinguishing the major differences between ItemCreated and ItemDataBound events

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jon
Top achievements
Rank 1
answered on 21 Sep 2010, 08:09 PM
So, setting the event handler in markup like the following won't work, correct? It doesn't work for me, but, it seems counter intuitive. I guess the event handler has to be set in code?

<telerik:RadComboBox ID="StatusRadComboBox" runat="server" SelectedValue='<%# Bind("Status") %>'
                                    AutoPostBack="True" OnSelectedIndexChanged="StatusRadComboBox_SelectedIndexChanged">
0
Princy
Top achievements
Rank 2
answered on 22 Sep 2010, 06:54 AM
 Hello Jon,

The SelectedIndexChanged event of combo will fire even if added from mark-up. I am not sure about your complete scenario.

Could you please paste your code that you are trying? Is it happening for a specific browser?

Thanks,
Princy.
Tags
Grid
Asked by
Mala
Top achievements
Rank 1
Answers by
Martin
Telerik team
Jon
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or