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

Adding SelectedItemChanged event to a radComboBox within a userControl editForm

2 Answers 267 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis-Philippe
Top achievements
Rank 1
Louis-Philippe asked on 21 Feb 2011, 10:41 PM
Hello,
I'm using a userControl as an editForm for my radGrid. In the said editForm, I have a bunch of other userControl with contains custom radComboBox. I'm trying to add server-side SelectedItemChanged event to those comboBox, but the event never gets fired. Here's the way I'm adding the event:

dataComboBox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(this.dataComboBox_SelectedItemChanged);

Since I use those userControl elsewhere, I know that the syntax isn't the issue. I tried to add the event withing my editForm userControl at a bunch of different place, such as in DataBinding and OnInit event. I also tried to add the event in the ItemDataBound event of my radGrid without any success. How or where can I add my SelectedItemChanged?

Thank you for your help,
LP

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Feb 2011, 06:07 AM
Hello Louis,

Try the following code snippet to attach SelectedIndexChaged event for RadComboBox inside UserControl.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editedItem = (GridEditFormItem)e.Item;
            UserControl userControl = (UserControl)editedItem.FindControl(GridEditFormItem.EditFormUserControlID);
            RadComboBox combo = (RadComboBox)userControl.FindControl("RadComboBox1");//access RadComboBox using its ID
            combo.AutoPostBack = true;
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
        }
    }
 
    void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        
    }

Thanks,
Princy.
0
Louis-Philippe
Top achievements
Rank 1
answered on 22 Feb 2011, 02:56 PM
Thank you! My problem wasn't adding the event the right way or event at the right place, what did the trick was adding
combo.AutoPostBack =
true;

Won't forget that one...

Thanks for your help and have a nice day,
LP
Tags
Grid
Asked by
Louis-Philippe
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Louis-Philippe
Top achievements
Rank 1
Share this question
or