RadComboBox in Formview - SelectedIndexchanged

9 posts, 1 answers
  1. Michael
    Michael avatar
    19 posts
    Member since:
    Jun 2012

    Posted 13 Dec 2012 Link to this post

    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
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 13 Dec 2012 Link to this post

    Hello Michael,

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

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    19 posts
    Member since:
    Jun 2012

    Posted 14 Dec 2012 Link to this post

    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


     

  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 18 Dec 2012 Link to this post

    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.
  6. Answer
    christian
    christian avatar
    13 posts
    Member since:
    May 2009

    Posted 19 Dec 2012 Link to this post

    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!
  7. Michael
    Michael avatar
    19 posts
    Member since:
    Jun 2012

    Posted 27 Dec 2012 Link to this post

    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
  8. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 02 Jan 2013 Link to this post

    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.
  9. Michael
    Michael avatar
    19 posts
    Member since:
    Jun 2012

    Posted 07 Jan 2013 Link to this post

    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?

  10. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 09 Jan 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017