LoadOnDemand + SelectedValue Issue

8 posts, 0 answers
  1. Michael
    Michael avatar
    58 posts
    Member since:
    Jan 2008

    Posted 07 Feb 2008 Link to this post

    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!
  2. Michael
    Michael avatar
    58 posts
    Member since:
    Jan 2008

    Posted 07 Feb 2008 Link to this post

    Any ideas?  It's probably easy but I can't figure this one out.
  3. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 07 Feb 2008 Link to this post

    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
  4. Mike
    Mike avatar
    6 posts
    Member since:
    Jan 2008

    Posted 08 Feb 2008 Link to this post

    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.  
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Feb 2008 Link to this post

    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
  6. Mike
    Mike avatar
    6 posts
    Member since:
    Jan 2008

    Posted 12 Feb 2008 Link to this post

    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.  
  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 14 Feb 2008 Link to this post

    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
  8. iTools
    iTools avatar
    28 posts
    Member since:
    Jun 2007

    Posted 16 Jun 2010 Link to this post

    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.
Back to Top