4 Answers, 1 is accepted
0
Hi Duncan,
In general get_items().get_count() should return the number of RadComboBox items.
Maybe with some more details about your scenario we will be able to help you?
Can you provide us some working code that illustrates your implementation?
Regards,
Kalina
the Telerik team
In general get_items().get_count() should return the number of RadComboBox items.
Maybe with some more details about your scenario we will be able to help you?
Can you provide us some working code that illustrates your implementation?
Regards,
Kalina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Duncan
Top achievements
Rank 2
answered on 17 Feb 2012, 04:59 PM
I have a script that hides the prop down if no items are found... If there are items, the script is supposed to resize the height of the dropdown. However... Even if there are only 2 items being shown, sender.get_items().get_count() = 78, whihc is the number of total item that are originally bound to the control.
Here is my implementation:
This is my control, LoadOnDemand is set to true:
And this is where it is bound in the code behind:
Duncan
Here is my implementation:
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> function OnClientItemsRequestedHandler(sender, eventArgs) { if (sender.get_visibleItems().length == 0) { sender.hideDropDown() } else { //set the max allowed height of the combo var max_allowed_height = 200; //this is the single item's height var single_item_height = 22; var calculatedHeight = sender.get_items().get_count() * single_item_height; var dropDownDiv = sender.get_dropDownElement(); if (calculatedHeight > max_allowed_height) { setTimeout( function () { dropDownDiv.firstChild.style.height = max_allowed_height + "px"; }, 20 ); } else { setTimeout( function () { dropDownDiv.firstChild.style.height = calculatedHeight + "px"; }, 20 ); } } } </script></telerik:RadScriptBlock>This is my control, LoadOnDemand is set to true:
<telerik:RadComboBox ID="cboTags" runat="server" CssClass="combo" AutoPostBack="true" Width="394px" EnableEmbeddedBaseStylesheet="False" EnableEmbeddedSkins="False" EnableTheming="False" MarkFirstMatch="True" ShowMoreResultsBox="False" ShowToggleImage="False" EmptyMessage="Tag Name" DropDownCssClass="combo-input-drop" Filter="Contains" DropDownWidth="410" EnableAutomaticLoadOnDemand="False" EnableLoadOnDemand="True" OffsetX="-38" OffsetY="-3" ShowDropDownOnTextboxClick="False" DataTextField="Tag" DataValueField="TagId" EnableTextSelection="False" NoWrap="True" AllowCustomText="True" Height="208" OnItemsRequested="cboTags_ItemsRequested" ValidationGroup="Form" OnClientItemsRequesting="OnClientItemsRequestedHandler" OnClientItemsRequested="OnClientItemsRequestedHandler" OnClientDropDownOpening="OnClientItemsRequestedHandler" ShowWhileLoading="False"> <ExpandAnimation Type="none" /> <CollapseAnimation Type="none" /></telerik:RadComboBox>And this is where it is bound in the code behind:
public void Tags_DataBind(){ TagsBL tagsbl = new TagsBL(conn); cboTags.DataSource = tagsbl.GetAllTags(contextuser); cboTags.DataBind(); cboTags.SortItems();}protected void cboTags_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e){ Tags_DataBind();}tagsbl.GetAllTags(contextuser) returns a list of tags... 78 in total. However, as the user is typing, this gets filtered down.Duncan
0
Accepted
Hello Duncan,
Please excuse me for the delay.
As far as I understand you want to re \size the RadComboBox dropdown after the items have been requested.
I am afraid that you cannot make this with custom logic, but you can remove the Height property of the control and set the MaxHeight property instead.
Based on this online demo (the "Product" combo) I prepared a small sample for you:
Please find the full sample attached.
Regards,
Kalina
the Telerik team
Please excuse me for the delay.
As far as I understand you want to re \size the RadComboBox dropdown after the items have been requested.
I am afraid that you cannot make this with custom logic, but you can remove the Height property of the control and set the MaxHeight property instead.
Based on this online demo (the "Product" combo) I prepared a small sample for you:
<telerik:RadComboBox ID="RadComboBoxProduct" runat="server" Width="200px" MaxHeight="300px" DropDownWidth="298px" EmptyMessage="Choose a Product" HighlightTemplatedItems="true" EnableLoadOnDemand="true" Filter="StartsWith" OnItemsRequested="RadComboBoxProduct_ItemsRequested"></telerik:RadComboBox>protected void RadComboBoxProduct_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) { string sqlSelectCommand = "SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock] from [Products] WHERE [ProductName] LIKE @text + '%' ORDER BY [ProductName]"; SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings["NorthwindConnectionString2"].ConnectionString); adapter.SelectCommand.Parameters.AddWithValue("@text", e.Text); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); foreach (DataRow dataRow in dataTable.Rows) { RadComboBoxItem item = new RadComboBoxItem(); item.Text = (string)dataRow["ProductName"]; item.Value = dataRow["ProductID"].ToString(); RadComboBoxProduct.Items.Add(item); item.DataBind(); } }Please find the full sample attached.
Regards,
Kalina
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.
0
Duncan
Top achievements
Rank 2
answered on 23 Feb 2012, 09:31 PM
Awesome. I did not know that property existed... That's close enough... Thanks