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

Load on demand and selected item in selectedindexchanged

3 Answers 226 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 04 Mar 2010, 04:58 AM
Hi guys,

I have a RadComboBox as follows
<radcontrol:RadComboBox ID="MessageRecepientsSelectorComboBox" runat="server" EnableLoadOnDemand="true"    
    LoadingMessage="Loading..." EmptyMessage="Please enter recepient(s) for the message..."   
    OnItemsRequested="MessageRecepientsSelectorComboBox_OnItemsRequested" Width="450" ShowDropDownOnTextboxClick="false" 
    Filter="StartsWith" OnSelectedIndexChanged="MessageRecepientsSelectorComboBox_OnSelectedIndexChanged" 
    AutoPostBack="true" EnableItemCaching="true"></radcontrol:RadComboBox> 

Which is inside a Load on demand RadPageView (incase that is relevant).

The ComboBox works fine for getting and matching values (names in this case) however in the SelectedIndexChanged my RadComboBox.SelectedItem is null, RadComboBox.Items.Count = 0. See below

protected void MessageRecepientsSelectorComboBox_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)  
    {  
        RadComboBox recepientSelectorComboBox = (RadComboBox)sender;  
        if (!e.Text.Equals("") && e.Text.Length >= 1)  
        {  
            List<Controls_RecepientsSelectorAJAXDropDownResult> potentialRecepients = MemberContactStaticRepository.GetRecepientsForAJAXSelector(53, e.Text);  
            RadComboBoxItem currentItem = new RadComboBoxItem(); //stop re initialising var in loop  
            for(int i = 0;i < potentialRecepients.Count();i++)  
            {  
                currentItem = new RadComboBoxItem(potentialRecepients[i].UserName, potentialRecepients[i].UserID.ToString());  
                //currentItem.Attributes["ContactType"] = "User";  
                recepientSelectorComboBox.Items.Add(currentItem);  
            }  
        }  
    } 

protected void MessageRecepientsSelectorComboBox_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        RadComboBox recepientBox = (RadComboBox)sender;  
        //RadComboBoxItem selectedItem = MessageRecepientsSelectorComboBox.FindItemByValue(e.Value); //finds nothing == null  
        //MessageRecepientsSelectorComboBox.Items.Count; // is 0          
        //MessageRecepientsSelectorComboBox.SelectedIndex;//returns -1       
    } 

Please note in the OnSelectedIndexChanged it is all commented out but the comments beside it tell you what happens.
I need it to have a SelectedItem so that i can access the Attributes i need to set.

Thanks in advance,
Pete

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 09 Mar 2010, 08:24 AM
Hi Peter,

ComboBox items are not accessible on the server-side when loading them on demand

What you can do in this case is to use hidden fields and store the necessary attributes in their values.

Let me know if I can assist you further.

Sincerely yours,
Veskoni
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Bala
Top achievements
Rank 1
answered on 12 Sep 2012, 07:12 AM
Hi,

I am also facing the same issue. Please assist me in fixing this issue.

Yours Sincerely
Mohamed
0
Ivana
Telerik team
answered on 12 Sep 2012, 08:50 AM
Hello Bala,

The help article provided by Veselin (ComboBox items are not accessible on the server-side when loading them on demand) explains a lot on why it is essential to not have the items of RadComboBox accessible on the server when the control is loaded on demand.

The help article also explains on the RadComboBox's properties that are accessible on the server.

I hope you'll  find this helpful!

Regards,
Ivana
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
Peter
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Bala
Top achievements
Rank 1
Ivana
Telerik team
Share this question
or