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

dynamically loading cascading RadComboBoxes when web pages first loads

2 Answers 68 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve Holdorf
Top achievements
Rank 1
Steve Holdorf asked on 27 Nov 2012, 03:54 PM
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;
    ComboBoxProgram.DataBind();  
}

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?

Thanks,


Steve Holdorf

2 Answers, 1 is accepted

Sort by
0
Steve Holdorf
Top achievements
Rank 1
answered on 27 Nov 2012, 07:24 PM
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!

Thanks,

Steve

0
Dimitar Terziev
Telerik team
answered on 30 Nov 2012, 07:56 AM
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.
Tags
ComboBox
Asked by
Steve Holdorf
Top achievements
Rank 1
Answers by
Steve Holdorf
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or