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

RadComboBox in Repeater with Autocomplete

1 Answer 171 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 14 Oct 2012, 08:13 PM
Hi All,

Here's what I got:

I have a RadCombobox that has three specific challenges:  (1) the recordset is so large that I need LoadOnDemand-style functionality and (2) the combobox needs to be inside a asp.net repeater.  Since it needs to be in a repeater, I do not see this demo working: http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultvb.aspx

Here is the technique I'm currently attempting:

1.  Here is the RadCombobox declaration:

<telerik:RadComboBox ID="PositionRCB" Runat="server" OnClientItemsRequesting="onItemsRequesting" DataSourceID="PositionDS" DataTextField="Info" DataValueField="PK" MarkFirstMatch="True" Width="125px" ShowToggleImage="True" Filter="Contains" EnableAutomaticLoadOnDemand="True" ItemsPerRequest="15">
</telerik:RadComboBox>

2. When the user types, OnClientItemsRequesting fires:

<script type="text/javascript">
 
    function onItemsRequesting(sender, eventArgs) {
 
        var positionText = eventArgs.get_text();
        document.getElementById("<%= HiddenTB_Position.ClientID %>").value = positionText
         
    }
 
</script>  


3.  The JS above writes the user's typing to the following hidden textbox:

<asp:TextBox ID="HiddenTB_Position" runat="server" Text="Grot"></asp:TextBox>


4. Then, I'm trying to get the following DS declaration to update my RadCombobox:

<asp:SqlDataSource ID="PositionDS" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseCargoMM1 %>" SelectCommand="usp_PickCity" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="HiddenTB_Position" PropertyName="Text" Type="String" Name="Param1" />
    </SelectParameters>
</asp:SqlDataSource>

So, the bottom line is that the EnableAutomaticLoadOnDemand the property does not seem to be "re-firing" my datasource with the users typed values.  I'm wondering if (1) their is a way to force these RadComboboxes in the repeaters to fire when the JS above fires or (2) their is another technique that might work.

Thanks a ton for the help!

Jim

1 Answer, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 17 Oct 2012, 02:47 PM
Hi James,

As far as I understand - you want to nest RadComboBox with Automatic Load On Demand in Repeater and there has to be an initially selected item in the combo.

There are two things in your code that I would like to comment:
At first - the simultaneous usage of LoadOnDemand (AutomaticLoadOnDemand),  MarkFirstMatch and Filter is not recommended.  Simply by design these features do the same thing – they filter items. LoadOnDemand makes this at server-side; MarkFirstMatch and Filter filter items at client-side(with JavaScript).
Additionally - When you set the text in RadComboBox input at OnClientItemsRequested in fact you force the control always to request items only with this text even if user types something different.

I am suggesting you set the default selection in RadComboBox at Repeater.ItemDataBound event handler:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        CustomerData data = e.Item.DataItem as CustomerData;
        RadComboBoxItem item = new RadComboBoxItem(data.Region, data.RegionID.ToString());
 
        ((RadComboBox)e.Item.FindControl("PositionRCB")).Items.Add(item);
        item.Selected = true;
             
    }
 
}

Then if user deletes the text in combo input - a new request for items will be performed and all items will be visible in control dropdown – please take a look at this video.

You can download the sample I have prepared and give it a try.
If your case is different – please modify the sample to represent your scenario and send it back to me in a support ticket with more detailed description of the issue.


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.
Tags
ComboBox
Asked by
James
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or