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

RadCombo google style autopopulate

3 Answers 56 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gregor Suttie
Top achievements
Rank 1
Gregor Suttie asked on 23 Apr 2010, 11:56 AM
I have a radcombo box which is doing the ajax autosuggest successfully, however when it doesnt find any results can I populate the text box with "no results found" or something similar?

3 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 28 Apr 2010, 06:44 PM
Hi Gregor Suttie,

Could you please explain your implementation of the "autosuggest" feature in more details and paste your code here?
Thank you in advance.

All the best,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 29 Apr 2010, 05:16 AM
(this is from the combo webservice Live Demo installed with the radcontrols)

So I guess after var allCustomers you could just check the Count of the collection then if 0 add in a  blank "No Records" RadComboBoxItemData object to that collection...then return that.  Or I think perhaps just changing the Status Message at the bottom if Count == 0 might work too (as it wouldn't be selectable...) but whatever floats your telerik boat :)

    [OperationContract] 
    public RadComboBoxData LoadData(RadComboBoxContext context) 
    { 
        //The RadComboBoxData object contains all required information for load on demand: 
        // - the items  
        // - are there more items in case of paging 
        // - status message to be displayed (which is optional) 
        RadComboBoxData result = new RadComboBoxData(); 
        NorthwindDataContext northwind = new NorthwindDataContext(); 
 
        //Get all items from the Customers table. This query will not be executed untill the ToArray method is called. 
        var allCustomers = from customer in northwind.Customers 
                           orderby customer.ContactName 
                           select new RadComboBoxItemData 
                                    { 
                                        Text = customer.ContactName 
                                    }; 
 
 
        //In case the user typed something - filter the result set 
        string text = context.Text; 
        if (!String.IsNullOrEmpty(text)) 
        { 
            allCustomers = allCustomers.Where(item => item.Text.StartsWith(text)); 
        } 
        //Perform the paging 
        // - first skip the amount of items already populated 
        // - take the next 10 items 
        int numberOfItems = context.NumberOfItems; 
        var customers = allCustomers.Skip(numberOfItems).Take(10); 
 
        //This will execute the database query and return the data as an array of RadComboBoxItemData objects 
        result.Items = customers.ToArray(); 
 
 
        int endOffset = numberOfItems + customers.Count(); 
        int totalCount = allCustomers.Count(); 
 
        //Check if all items are populated (this is the last page) 
        if (endOffset == totalCount) 
            result.EndOfItems = true
 
        //Initialize the status message 
        result.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>"
                                       endOffset, totalCount); 
 
        return result; 
    } 


However if you mean you have a textbox somewhere else on your page you want to populate with info from a blank combo, this function should trigger after the LoadOnDemand and you can manipulate it however you want...
0
Kalina
Telerik team
answered on 04 May 2010, 10:22 AM
Hi,

You can try handling OnClientItemsRequested event, clear selection and set the empty message property if there are no RadComboBox items found:

<telerik:RadComboBox ID="RadComboBox1" runat="server"
    EmptyMessage=" Select "
    OnItemsRequested="RadComboBox1_ItemsRequested"
    MarkFirstMatch="true"
    EnableLoadOnDemand="true"
    OnClientItemsRequested="OnClientItemsRequestedHandler"
    OnClientKeyPressing="OnClientKeyPressingHandler">
</telerik:RadComboBox>

function OnClientItemsRequestedHandler(sender, eventArgs) {
    if (sender.get_items().get_count() < 1) {
 
        sender.set_emptyMessage("no items found");
        sender.set_text("");
        sender.clearSelection();
    }
}

Then you can clear the empty message at OnClientKeyPressing event:

function OnClientKeyPressingHandler(sender, eventArgs)
{
     if(sender.get_text() == sender.get_emptyMessage())
     {
        sender.set_text("");
     }
}

I hope this helps.

Kind regards,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
Gregor Suttie
Top achievements
Rank 1
Answers by
Kalina
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or