For some reason the dropdown is still coming up on my ComboBoxes even though they're not databound / have no items in them.
How can I stop the dropdown from displaying when there are no items in it?
<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?
7 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 02 Jan 2009, 11:08 AM
Hi Rick,
Please try the following JavaScript in order to prevent opening the dropdown when there is no items in RadComboBox.
JavaScript:
Thanks,
Princy.
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.
0
Rick
Top achievements
Rank 1
answered on 02 Jan 2009, 12:33 PM
Thanks Princy,
Though I might suggest the following amendment, which allows the function to be added to an external file and utilised anywhere
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?
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?
0
Rick
Top achievements
Rank 1
answered on 05 Jan 2009, 01:51 PM
Could someone please confirm whether or not the above is a bug?
0
Accepted
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.
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.
0
Rick
Top achievements
Rank 1
answered on 05 Jan 2009, 02:32 PM
That's a good point, cheers
0
Ralf
Top achievements
Rank 1
answered on 09 Dec 2011, 06:28 PM
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
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
0
Kevin
Top achievements
Rank 2
answered on 09 Dec 2011, 07:15 PM
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.
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.