I have two related RadComboBoxes as following:
<
telerik:RadAjaxManagerProxy
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadDropDownParameterX"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxCountries"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxSites"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxRts"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxMachines"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxProtocols"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadComboBoxCountries"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadCodeBlock1"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadCodeBlock2"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadComboBoxSites"
LoadingPanelID
=
"AjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
...
</
telerik:RadAjaxManagerProxy
>
...
<
telerik:RadAjaxLoadingPanel
ID
=
"AjaxLoadingPanel1"
runat
=
"server"
Skin
=
"BlackMetroTouch"
>
</
telerik:RadAjaxLoadingPanel
>
...
<
div
class
=
"right"
>
<
span
>Select X-parameter</
span
>
<
telerik:RadDropDownList
ID
=
"RadDropDownParameterX"
runat
=
"server"
DropDownHeight
=
"120px"
Width
=
"120px"
Skin
=
"BlackMetroTouch"
DropDownWidth
=
"120px"
OnSelectedIndexChanged
=
"RadDropDownParameterX_SelectedIndexChanged"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:DropDownListItem
Text
=
"Countries"
Value
=
"Countries"
Selected
=
"true"
/>
<
telerik:DropDownListItem
Text
=
"Sites"
Value
=
"Sites"
/>
<
telerik:DropDownListItem
Text
=
"Rts"
Value
=
"Rts"
/>
<
telerik:DropDownListItem
Text
=
"Machines"
Value
=
"Machines"
/>
<
telerik:DropDownListItem
Text
=
"Protocols"
Value
=
"Protocols"
/>
</
Items
>
</
telerik:RadDropDownList
>
...
<
div
class
=
"combo countries"
>
<
telerik:RadComboBox
ID
=
"RadComboBoxCountries"
runat
=
"server"
AutoPostBack
=
"True"
onselectedindexchanged
=
"RadComboBoxCountries_SelectedIndexChanged"
CheckBoxes
=
"true"
EnableCheckAllItemsCheckBox
=
"true"
Label
=
"Country"
Skin
=
"BlackMetroTouch"
>
</
telerik:RadComboBox
>
<
div
class
=
"subv"
><
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
> <%= SelectedCountriesText %></
telerik:RadCodeBlock
></
div
>
</
div
>
<
div
class
=
"combo sites"
>
<
telerik:RadComboBox
ID
=
"RadComboBoxSites"
runat
=
"server"
CheckBoxes
=
"true"
AutoPostBack
=
"true"
onselectedindexchanged
=
"RadComboBoxSites_SelectedIndexChanged"
EnableCheckAllItemsCheckBox
=
"true"
Label
=
"Site"
Skin
=
"BlackMetroTouch"
>
</
telerik:RadComboBox
>
<
div
class
=
"subv"
><
telerik:RadCodeBlock
ID
=
"RadCodeBlock2"
runat
=
"server"
> <%= SelectedSitesText %></
telerik:RadCodeBlock
></
div
>
</
div
>
What i am trying to achieve is to have the second comboBox (RadComboBoxSites) populated upon selected Values of first comboBox.
Tried to achive that by deleting all items of RadComboBoxSites each time a SelectedIndexChanged event is occured on comboBox RadComboBoxCountries in the way depicted below:
Protected
Sub
RadComboBoxCountries_SelectedIndexChanged(
ByVal
o
As
Object
,
ByVal
e
As
Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
If
(RadDropDownParameterX.SelectedValue.Equals(
"Sites"
))
Dim
collectionPopulatedSites = RadComboBoxSites.Items
For
each s
In
collectionPopulatedSites
Dim
RadComboBoxSite
As
RadComboBoxItem = RadComboBoxSites.Items.FindItemByValue(s.Value)
If
RadComboBoxSite IsNot
Nothing
Then
RadComboBoxSite.Remove
End
If
Next
' get new list of selected countries
Dim
collectionSelectedCountries = RadComboBoxCountries.CheckedItems
For
each c in collectionSelectedCountries
Dim
listaCountrySites
As
List(Of AffideaGeneralWeb.BLL.General.Sites)
listaCountrySites = GetAllCountrySites(c.Value)
For
each s in listaCountrySites
Dim
RadComboBoxSite
As
RadComboBoxItem = RadComboBoxSites.Items.FindItemByValue(s.ID)
If
RadComboBoxSite
Is
Nothing
Then
RadComboBoxSite =
New
RadComboBoxItem()
RadComboBoxSite.Text = s.Title
RadComboBoxSite.Value = s.ID
RadComboBoxSites.Items.Add(RadComboBoxSite)
End
If
Next
Next
End
If
End
Sub
However when i am trying to "RadComboBoxSite.Remove" i am getting an exception:
An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code. Additional information: The collection has changed, the enumeration operation may not be performed
Is there any working example of related comboBoxes (handles in the server side)?
How could i delete all items of second comboBox and re-build it, each time the user alters selection on the first comboBox?