Autocomplete for ASP.NET RADListBox control

6 posts, 0 answers
  1. Sean Severson
    Sean Severson avatar
    56 posts
    Member since:
    Aug 2009

    Posted 26 Aug 2009 Link to this post

    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
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Sep 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean Severson
    Sean Severson avatar
    56 posts
    Member since:
    Aug 2009

    Posted 01 Sep 2009 Link to this post

    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

  5. Sean Severson
    Sean Severson avatar
    56 posts
    Member since:
    Aug 2009

    Posted 01 Sep 2009 Link to this post

    Got it!  item.scrollIntoView

    Sean M. Severson
  6. Jeff P
    Jeff P avatar
    37 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2010 Link to this post

    How did you set the attribute?
  7. Jonathan Torres
    Jonathan Torres avatar
    5 posts
    Member since:
    Jul 2009

    Posted 01 Jul 2010 Link to this post

    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();
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017