dynamically loading cascading RadComboBoxes when web pages first loads

3 posts, 0 answers
  1. Steve Holdorf
    Steve Holdorf avatar
    119 posts
    Member since:
    Apr 2010

    Posted 27 Nov 2012 Link to this post

    I have 3 RadComboBoxes on a web page. I have everything set in the SelectedIndexChanged of the first combobox to fill and select and load the  list of Item of the second combobox, same with the second to the third. What I have is cascading comboboxes that on selection of the first combobox's item it's SelectedIndexChange event loads all of that item.values in the second combobox that are referenced by the selected item.value (or e.value) of the first combobox. Also, the second to the third works the same way. What I need to do is on the page_load of the webpage have the cascade combobox selections take place. How can this be done on page_load and then once the page is loaded? Example of code for the first combobox is shown (note: the second to the third follows the same model) below:

    protected void ComboBoxGroup_SelectedIndexChanged (object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        GroupProgram.Item proItem = new GroupProgram.Item(sqlConn, Convert.ToInt32(e.Value));

        ComboBoxProgram.DataValueField = Program.Const_ProgramID;
        ComboBoxProgram.DataTextField = Program.Const_ProgramText;

        ComboBoxProgram.DataSource = proItem.List;

    Now, as you can see when the user selects a Group combobox item it's selectedIndexChange event is called and the Program combobox has its bound list pulled from the e.value ID field. The problem is that on page load I will set the Group combobox selected  item in the onLoad event; however, I need to know how to call it's selectedIndexChanged event dynamically when it's item value is set.
    Also, what is the best way to handle the 3 cascading radcomboxes after the page has loaded?


    Steve Holdorf
  2. Steve Holdorf
    Steve Holdorf avatar
    119 posts
    Member since:
    Apr 2010

    Posted 27 Nov 2012 Link to this post

    As a first pass what I am doing is creating a RadComboBoxSelectedIndexChangeEventArgs object and setting the bound items value then passing that to the SelectedIndexChanged event and calling that event manually in the Page_Load event. This does not seem to be the way to go because in the page_load event it seems that the second combobox is set correctly based on the value of the first comboboxes' selection; however, no action takes place with the third combobox as far as successful cascading. See code below:

    Page_Load (object sender, EventArgs e)

    // Use 5 as a test for the combobox item with a value of 5
    ComboBox1.SelectedValue = 5;

    // Create the combobox event arg
    RadComboBoxSelectedIndexChangeEventArgs ea = new RadComboBoxSelectedIndexChangeEventArgs("", "", ComboBox1.SelectedValue, "1");

    // Call the event manually for the first combobox
    ComboBox1_SelectedIndexChanged(ComboBox1, ea);

    // Do the same for the second combobox as I am doing above for the first
    ea = new RadComboBoxSelectedIndexChangeEventArgs("", "", ComboBox2.SelectedValue, "1");

    ComboBox2_SelectedIndexChanged(ComboBox2, ea);

    There has to be a better way of doing three radcombobox cascading but any help would be great!



  3. Dimitar Terziev
    Dimitar Terziev avatar
    1268 posts

    Posted 30 Nov 2012 Link to this post

    Hello Steve,

    Calling event handler functions manually is a bad practice. When you have a custom logic which is implemented in an event handler, but it should be used not only when this event is fired its better to be extracted in a separate method which could be called whenever needed.

    All the best,
    Dimitar Terziev
    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