Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

RadComboBox remove all items and repopulate

$
0
0

I have two related RadComboBoxes as following:

<telerik:RadAjaxManagerProxyID="RadAjaxManager1"runat="server">
        <AjaxSettings>
            <telerik:AjaxSettingAjaxControlID="RadDropDownParameterX">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxCountries"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxSites"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxRts"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxMachines"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxProtocols"LoadingPanelID="AjaxLoadingPanel1"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSettingAjaxControlID="RadComboBoxCountries">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControlControlID="RadCodeBlock1"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadCodeBlock2"LoadingPanelID="AjaxLoadingPanel1"/>
                     <telerik:AjaxUpdatedControlControlID="RadComboBoxSites"LoadingPanelID="AjaxLoadingPanel1"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
            ...
</telerik:RadAjaxManagerProxy>
...
<telerik:RadAjaxLoadingPanelID="AjaxLoadingPanel1"runat="server"Skin="BlackMetroTouch">
</telerik:RadAjaxLoadingPanel>
...
<divclass="right">
    <span>Select X-parameter</span>
    <telerik:RadDropDownListID="RadDropDownParameterX"runat="server" 
        DropDownHeight="120px"Width="120px"Skin="BlackMetroTouch"DropDownWidth="120px"
            OnSelectedIndexChanged="RadDropDownParameterX_SelectedIndexChanged"
            AutoPostBack="true">
            <Items>
                <telerik:DropDownListItemText="Countries"Value="Countries"Selected="true"/>
                <telerik:DropDownListItemText="Sites"Value="Sites"/>
                <telerik:DropDownListItemText="Rts"Value="Rts"/>
                <telerik:DropDownListItemText="Machines"Value="Machines"/>
                <telerik:DropDownListItemText="Protocols"Value="Protocols"/>
            </Items>
</telerik:RadDropDownList>
...    
<divclass="combo countries">
    <telerik:RadComboBoxID="RadComboBoxCountries"runat="server"
        AutoPostBack="True"
        onselectedindexchanged="RadComboBoxCountries_SelectedIndexChanged"
        CheckBoxes="true"EnableCheckAllItemsCheckBox="true"
        Label="Country"Skin="BlackMetroTouch">                           
    </telerik:RadComboBox>
    <divclass="subv"><telerik:RadCodeBlockID="RadCodeBlock1"runat="server"> <%= SelectedCountriesText %></telerik:RadCodeBlock></div>
</div>
             
<divclass="combo sites">
    <telerik:RadComboBoxID="RadComboBoxSites"runat="server"
        CheckBoxes="true"
        AutoPostBack="true"
        onselectedindexchanged="RadComboBoxSites_SelectedIndexChanged"
        EnableCheckAllItemsCheckBox="true"
        Label="Site"Skin="BlackMetroTouch">
    </telerik:RadComboBox>
    <divclass="subv"><telerik:RadCodeBlockID="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:

ProtectedSubRadComboBoxCountries_SelectedIndexChanged(ByValo AsObject, ByVale AsTelerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
    If(RadDropDownParameterX.SelectedValue.Equals("Sites"))
        DimcollectionPopulatedSites = RadComboBoxSites.Items
        Foreach s IncollectionPopulatedSites
            DimRadComboBoxSite AsRadComboBoxItem = RadComboBoxSites.Items.FindItemByValue(s.Value)
            IfRadComboBoxSite IsNot NothingThen
                RadComboBoxSite.Remove
            EndIf
        Next
             
        ' get new list of selected countries
        DimcollectionSelectedCountries = RadComboBoxCountries.CheckedItems
        Foreach c in collectionSelectedCountries
 
            DimlistaCountrySites AsList(Of AffideaGeneralWeb.BLL.General.Sites)
            listaCountrySites = GetAllCountrySites(c.Value)
                 
            Foreach s in listaCountrySites
                     
                DimRadComboBoxSite AsRadComboBoxItem = RadComboBoxSites.Items.FindItemByValue(s.ID)
 
                IfRadComboBoxSite IsNothingThen
                    RadComboBoxSite = NewRadComboBoxItem()
                    RadComboBoxSite.Text = s.Title
                    RadComboBoxSite.Value = s.ID
                    RadComboBoxSites.Items.Add(RadComboBoxSite)
                EndIf
                     
            Next
        Next
 
    EndIf
 
EndSub

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?


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>