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

Autocomplete for ASP.NET RADListBox control

5 Answers 241 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Sean Severson
Top achievements
Rank 1
Sean Severson asked on 26 Aug 2009, 02:50 PM
Our application provides users with a list of contacts.  The user would like to locate a specific contact by typing the first letter of the contact's name and have the list box jump to that item in the list.  I have not seen an autocomplete property for the ASP.NET RADListBox control.  Is there another method to support this functionality?

Sean M. Severson

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 01 Sep 2009, 11:21 AM
Hello Sean Severson,

Please find attached a sample project. Just start typing in the RadTextBox and it will automatically search and select the listbox item that matches.

Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sean Severson
Top achievements
Rank 1
answered on 01 Sep 2009, 04:05 PM

Veselin,

Thank you for the example.  I was able to modify it to work for most of what I need.  I modified the javascript to get the key pressed by the user and added an attribute, onkeypress, to the RadListBox on my form.

Here is the Javascript I used...

function filterListBox(sender, e) { 
    var list = $find("<%= lstUser.ClientID %>"); 
    var searchText = String.fromCharCode(event.keyCode); 
    var items = list.get_items(); 
    for (var i = 0; i < items.get_count(); i++) { 
        var item = items.getItem(i); 
        if (item.get_text().toLowerCase().startsWith(searchText.toLowerCase())) { 
        item.select(); 
        } 
    }
}

Now, instead of selecting all of the items, I need to scroll to the first item that matches.

Sean M. Severson

0
Sean Severson
Top achievements
Rank 1
answered on 01 Sep 2009, 04:22 PM
Got it!  item.scrollIntoView

Sean M. Severson
0
Craig
Top achievements
Rank 2
answered on 31 Mar 2010, 07:07 PM
How did you set the attribute?
0
Jonathan Torres
Top achievements
Rank 1
answered on 01 Jul 2010, 05:09 PM
Just a heads up, the posted code will scroll to the LAST item in the list that matches the search text.  If you want to stop at the first item found, then add a break; after the item.select();
Tags
ListBox
Asked by
Sean Severson
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Sean Severson
Top achievements
Rank 1
Craig
Top achievements
Rank 2
Jonathan Torres
Top achievements
Rank 1
Share this question
or