How to disable dropdown when not databound?

8 posts, 1 answers
  1. Rick
    Rick avatar
    49 posts
    Member since:
    Oct 2008

    Posted 02 Jan 2009 Link to this post

    For some reason the dropdown is still coming up on my ComboBoxes even though they're not databound / have no items in them.

     
    <telerik:RadComboBox ID="RadComboBox" DataSourceID="odsPopularProducts" Filter="Contains" 
              DataTextField="ProductName" DataValueField="ProductID" AllowCustomText="true" MaxHeight="300" 
              Width="205" OnSelectedIndexChanged="RadComboBoxProducts_SelectedIndexChanged" 
              AutoPostBack="true" DropDownWidth="300" OffsetX="-95" EmptyMessage="Select a Popular Product..." 
              runat="server">                                                                                                                 
    </telerik:RadComboBox> 

    How can I stop the dropdown from displaying when there are no items in it?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jan 2009 Link to this post

    Hi Rick,

    Please try the following JavaScript in order to prevent opening the dropdown when there is no items in RadComboBox.

    JavaScript:
    <script type="text/javascript"
    function OnClientDropDownOpening(sender, eventArgs) 
        var combo = $find("<%= RadComboBox.ClientID %>"); 
        items = combo.get_items(); 
        if(items.get_count()==0) 
        { 
             eventArgs.set_cancel(true); 
        } 
    </script> 


    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rick
    Rick avatar
    49 posts
    Member since:
    Oct 2008

    Posted 02 Jan 2009 Link to this post

    Thanks Princy,

    Though I might suggest the following amendment, which allows the function to be added to an external file and utilised anywhere

                function OnClientDropDownOpening(sender, eventArgs)  
                {  
                    items = sender.get_items();  
                    if(items.get_count()==0)                  
                         eventArgs.set_cancel(true);  
                }  

    Why isn't this built in as standard? Why would you want a drop down to display if there's nothing in the dropdown?

    Or in my case (where my MaxDropDownHeight is 300px) why would I want a dropdown of 300px to be displayed when there's nothing in the dropdown? That's surely a bug?
  5. Rick
    Rick avatar
    49 posts
    Member since:
    Oct 2008

    Posted 05 Jan 2009 Link to this post

    Could someone please confirm whether or not the above is a bug?
  6. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 05 Jan 2009 Link to this post

    Hi Rick,

    This is not a bug since a lot of customers rely on this feature to load on demand the items of RadComboBox. This is used frequently to reduce the total amount of combobox item which are initially rendered. When the user opens the combobox (which is initially empty) a request to the server side is made and the items are fetched.

    All the best,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Rick
    Rick avatar
    49 posts
    Member since:
    Oct 2008

    Posted 05 Jan 2009 Link to this post

    That's a good point, cheers
  8. Ralf
    Ralf avatar
    77 posts
    Member since:
    Jun 2012

    Posted 09 Dec 2011 Link to this post

    Hi,

    I have a load on demand scenario, and I need to prevent the dropdown form opening if no data was added. I need a behavior that opens the dropdown only if data/items was received. Is this possible?

    Best regards,
    Ralf
  9. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 09 Dec 2011 Link to this post

    Hello Ralf,

    To show the drop-down only when items were received you handle the OnClientItemsRequested event to show the drop-down is any items were added to the drop-down. You could also handle the OnClientItemsRequesting event to hide the drop-down as well.

    I hope that helps.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017