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

RadComboBox in Formview - SelectedIndexchanged

8 Answers 198 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 13 Dec 2012, 03:16 PM
Hi,

I'm currently trying to make the SelectedIndexchanged event available inside a Formview.
What i tried was adding an handler like:
(FormView1.Row.FindControl("rb_fvCustomer") as RadComboBox).AutoPostBack = true;
(FormView1.Row.FindControl("rb_fvCustomer") as RadComboBox).SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(customerCB_SelectedIndexChanged);


Including the defintion of the method:

private void customerCB_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
  // DoStuff();
}


It somehow does add the eventhandler but does not fire the according event when changing selection. Is DataBound the wrong place to apply the Even? Any hints about this issue?

regards, Michael

8 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 13 Dec 2012, 04:50 PM
Hello Michael,

You should probably handle the ItemCreated event and call your code there.

I hope that helps.
0
Michael
Top achievements
Rank 1
answered on 14 Dec 2012, 07:53 AM
Hi Kevin,

thanks for the hint. I tried that but no luck.

Here's the aspx:
<telerik:RadComboBox ID="rb_fvCustomer" runat="server"  DataSourceID="Customers" EnableAutomaticLoadOnDemand="true" ItemsPerRequest="10"  EnableVirtualScrolling="true" DataTextField="name" DataValueField="customerid"  ShowMoreResultsBox="true" Width="190px">                                </telerik:RadComboBox>


code behind (c#):
private void customerCB_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            //DoStuff();
        }
protected void FormView1_ItemCreated(object sender, EventArgs e)
        {
            if (FormView1.CurrentMode == FormViewMode.Insert)
            {
                RadComboBox myBox = FormView1.Row.FindControl("rb_fvCustomer") as RadComboBox;
                myBox.AutoPostBack = true;
                myBox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(customerCB_SelectedIndexChanged);
            }
        }

BTW, I should note the EnableLoadOnDemand is enabled, does that have any impact on making the selected indexchanged fire?

regards, Michael


 

0
Nencho
Telerik team
answered on 18 Dec 2012, 08:56 AM
Hello Michael,

Actually the suggestion that Kevin proposed is appropriate and suitable for the described scenario. I have prepared a sample project for you demonstrating the implementation of the functionality.  If you still have any difficulties achieving the desired functionality, could you provide us the entire implementation that you use at your end? Please find the sample attached.

Regards,
Nencho
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
Accepted
christian
Top achievements
Rank 1
answered on 19 Dec 2012, 06:17 AM
Hi,

Ouch, all my fault!!
 As yor project works and mine didn't i was attempting to send you a demo showing the behaviour when i found that it was the RequiredFieldValidators i was using. They prevented the PostBack from being executed.

Setting CauseValidation=false for my radcombo did the trick!

excusez moi!
0
Michael
Top achievements
Rank 1
answered on 27 Dec 2012, 06:59 AM
Hi,

one follow-up question.
It turns out that the selectedIndexchanged does sometimes not work when changing the selection for the first time after loading the page. It always works on upcoming changes AND  when debugging the project :(.
However, on the first try after laoding my page, my Ajaxloadingpanel comes up but after that, the selection is removed and no code within the event is executed. Ideas?

thanks in advance
0
Helen
Telerik team
answered on 02 Jan 2013, 09:48 AM
Hello Michael,

What is the exact version of the Telerik.Web.UI.dll and under which browser you have experienced the issue?
Do the SelectedIndexChanged event work without Ajax(EnableAjax=false).

Regards,
Helen
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
Michael
Top achievements
Rank 1
answered on 07 Jan 2013, 07:33 AM
Hallo Helen,

Thanks for your reply.

I'm using Telerik.Web.UI.dll v. 2012.3.1016.35

In the meantime i  have some further findings as i was able to recreate the issue with debugging enabled.
My RadCombo is nested in a Formview-InsertItemTemplate.

Scenario:

When getting to the InsertMode via the Formview (so not loaded in insert-mode on default) the sequence of the events is the following:

1) FormView1_ItemCreatet after opening the insert mode.
2) FormView1_ItemCreated by extending the combobox
3) SelectedINdexChanged is executed
4) FormView1_ItemCreated is executed once more. All changes done in 3) are undone and the combo is empty.

When re-selecting an entry then, it is just 1-3 and all is fine.

Also, when the formview is directly loaded in Insert mode, the sequence is just 1-3 and everything works as expected.

Hope this gives you a better idea. Any ideas?

0
Nencho
Telerik team
answered on 09 Jan 2013, 02:54 PM
Hello Michael,

Unfortunately, I was unable to replicate the experienced issue, base on the provided instructions. Do you reproduce the described problematic behavior with the previously provided sample? If not, could you modify it in a manner so we could observe the issue at our end and send it to us?

Regards,
Nencho
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
ComboBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Nencho
Telerik team
christian
Top achievements
Rank 1
Helen
Telerik team
Share this question
or