Solved

partial search in asp.net Listbox using javascript

Posted on 2008-10-28
8
701 Views
Last Modified: 2012-05-05
In normal cases If we have a listbox with 4 items as follows:

 1234

 456

 34567

 2345

and user selects first item in listbox and press 2 key 4th row will be highlighted. I have a listbox with items in a format ( code-description) e.g 1234-iteone,123-safeitem.I want to allow user to select first item in listbox and if user press saf then second row should be highlighted.

I  suppose I was able to explain properly. Let me know If you have any suggestion. All this need to be done using javascript functions without ajax etc.

0
Comment
Question by:needo_jee
  • 5
  • 3
8 Comments
 
LVL 12

Accepted Solution

by:
techExtreme earned 500 total points
ID: 22821246
Hello,
This is exactly what you need.
Go here
http://listbox-with-keybord-search.4wsearch.com/

It is free, has a demo link which opens a popup where the listbox is there and you can
start typing and partial search is done in it.

Hope it helped.

Happy Scripting!
0
 
LVL 12

Author Comment

by:needo_jee
ID: 22823118
Thanks for your reply. But in this demo listbox item are added alphabetically ... I have listbox with items like 123-abc, 234-def and I want that if user presses a first item should be selected and so on.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22823273
Hello,
It will work with number too, have you tried downloading it?

Also, as you told it will also select the item.  Only you have to wait till it gets a distinct item.
For example if you have two items 123abc and 123def,  you start pressing 1...2...3, it will ultimately filter the items out and you will have those two items in the list, then the moment you press 'a'  it will become 123a and the second item (123def ) will be filtered out and 123abc will be selected in the listbox.

As when you just type 12, it won't know what to select 123abc or 123def, so just need to give proper input to let it identify the exact item you are looking for.

Hope it helped.
0
 
LVL 12

Author Comment

by:needo_jee
ID: 22823495
I want to type 'a' and want abc selected. I dont want user type 123-a to get 123-a selected. besides there is no textbox. I have only listbox. user will select first item and click 'a' from keyboard and  123-a item will be selected. if user presses a second time next item starting with a will be selected (e.g 123-asia)and so on.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Author Comment

by:needo_jee
ID: 22824272
I have written following javascript code:

function autoSelect()
    {
     var keycode = event.keyCode;
     if(keycode < 65  || keycode > 90)
     {
      void(0);
     }
    else
    {
    var i=0;    
    var userPressed =  String.fromCharCode(keycode);
    var temp = [];    
   
    for (j = 0; j < document.Form1.ListBox1.options.length; j++)
           {  
           var arr = document.Form1.ListBox1.options[j].text.split("-");  
           var strToMatch = arr[1];
                 if(strToMatch.substring(0,1) == userPressed.toLowerCase())
                 {  
                                   
                 temp[i] = j;
                 i=i+1;
                  if(document.Form1.ListBox1.options[j].selected != true)
                  {
                    document.Form1.ListBox1.options[j].selected = true;
                    break;                
                   }                                
     
                 }                                                                          
           }
      }
   }

and here is how I use it :

  <asp:ListBox ID="ListBox1" runat="server" onkeydown="autoSelect();">

but It works for 2 items only like If i have 123-a,123-ab,123-abc,pressing a one time will select 123-a, pressing second time will select second one and thats it.

Any suggestion please?
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22825020
Hello,
In case of only listbox, I guess you need the asp.net list search extender.
Have a look at this demo:

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ListSearch/ListSearch.aspx

Just click inside the listbox once and start typing , it will start selecting on the basis of what you type.

Hope it helped
0
 
LVL 12

Author Comment

by:needo_jee
ID: 22827808
I dont want to use ajax for this.
0
 
LVL 12

Author Comment

by:needo_jee
ID: 22828923
Any suggestions please.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now