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

LoadOnDemand + SelectedValue Issue

7 Answers 376 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Michael asked on 07 Feb 2008, 01:26 PM
Pretty basic issue - just trying to retrieve the selected value of a RadComboBox on server-side.  Naturally my instinct was to try the SelectedValue but that returns "".  After doing some research through this forum I kind of understand why that is -- it's a client-side thing because of the LoadOnDemand and so the server knows nothing about the selected value.

After some more digging it seemed that the common response to this was to use the "Text" and "Value" properties of the combobox.  The Text property is available and works just fine, however I couldn't find a Value property which was driving me batty.

Eventually I found another thread that indicated the Value should be used on the "Items".  So I tried MyComboBox.Items(0).Value but I got an "Index out of range" error.

Can someone kindly clear up this issue for me?  Thanks!

7 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 2
answered on 07 Feb 2008, 04:38 PM
Any ideas?  It's probably easy but I can't figure this one out.
0
Veselin Vasilev
Telerik team
answered on 07 Feb 2008, 06:10 PM
Hello Michael,

The Value property was used in the "classic" combobox when the items are loaded on demand. In the Prometheus combobox the SelectedValue property should be used instead (in the code behind).

It works fine except one case: if you have an item/items defined in the aspx file (static items) and items loaded on demand. In this case the SelectedValue returns empty string. This is fixed in our latest internal build, so if this is your case - please open a formal support ticket and request the latest internal build.

If your case is different then please open a support ticket and attach a simple project demonstrating the problem.


Thanks

Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 09 Feb 2008, 02:20 AM
Did this issue go into Support, and was there a resolution?  I'm having the same problem, and I'm prepared to go so far as calling it a bug.

Here's what seems to be happening:  

1) Control is clicked, and values are loaded on demand.
2) Form posts back (in my case, using autopostback)
3) The list of items goes bye bye
4) Selected value is referenced, but selected value is pulled from Items[SelectedIndex] which is no longer there


Here's a couple functions from my project as an example:

protected void ddlCompany_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
    {  
        e.NumberOfItems += GetItemsRequested(ddlCompany, e.NumberOfItems);  
 
        string compareText = e.Text.ToUpper();  
 
        BindCompany(compareText, e.NumberOfItems);  
 
        e.Message = "Items 1 - " + e.NumberOfItems;  
    }  
 
    private void BindCompany(string compareText, int numItems)  
    {  
        var companies = (from b in AppBinding.CompanyList()  
                        where !string.IsNullOrEmpty(b.crmCode)  
                        && (b.name.ToUpper().Contains(compareText) || b.crmCode.ToUpper().Contains(compareText))  
                        && b.crmCode == "INGRAM04"  
                        orderby b.name  
                        select b).Take(numItems);  
 
        ddlCompany.DataSource = companies;  
        ddlCompany.DataBind();  
    } 


There are two scenarios we can have with this.

1) In page load call BindCompany("", 10)

If you do this, and select an item within the first 10 items it works perfectly.  On postback it rebinds to the list, and gives you the correct SelectedValue.  However, if you get an item farther down in the list tge SelectedValue is blank on postback because it is no longer there when you rebind.

2) In page load call BindCompany(ddlCompany.Text,  10)

If you do this, it never actually works.  

Hrm... there must be more to it than just SelectedIndex, or that would work because the same list is getting rebound and the index should still work.  
0
Veselin Vasilev
Telerik team
answered on 12 Feb 2008, 09:22 AM
Hello Mike,

Have you tried putting the BindCompany("", 10) in the if (!IsPostBack && !ddlCompany.IsCallBack) block of the Page_Load event?


Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 12 Feb 2008, 04:03 PM
There doesn't appear to be an IsCallback property on the Prometheus RadComboBox.

However, that wouldn't work anyway. If you don't rebind the list, there is no list, so the SelectedIndex is invalid and SelectedValue will be blank.

I also just noticed that if there is text in the ComboBox, and I click the Show More Results button another line is added to the list, but the other items aren't cleared out.  My code completely regenerates the list each time, so it looks like the client side display handling might be part of the problem here.  
0
Veselin Vasilev
Telerik team
answered on 14 Feb 2008, 08:30 AM
Hi Mike,

I think the best way to proceed is to isolate the problem in a small project and attach it to a formal support ticket.
We will test it locally and find a working solution for you.

Thanks

Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
iTools
Top achievements
Rank 1
answered on 17 Jun 2010, 01:33 AM
You need to check Page.IsPostBack and Page.IsCallBack if databinding to the RadComboBox in the Page Load event handler as detailed here. There is no IsCallBack property on the control itself.
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 2
Answers by
Michael
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Mike
Top achievements
Rank 1
iTools
Top achievements
Rank 1
Share this question
or