Requirement in Drop down list
-
Hi all, There is a small requirement in drop down list. Suppose I have bounded the employee names to the drop down list. Now I am searching for a name “Peter”. So if I press ‘p’ and then ‘e’ it should go to Peter’s name. But it goes to Elizabeth’s name. Is there any solution for that? Could anyone of you please help me on that? I am using .Net version 2.0 Thanks and Regards, Hariharan C
-
Hi all, There is a small requirement in drop down list. Suppose I have bounded the employee names to the drop down list. Now I am searching for a name “Peter”. So if I press ‘p’ and then ‘e’ it should go to Peter’s name. But it goes to Elizabeth’s name. Is there any solution for that? Could anyone of you please help me on that? I am using .Net version 2.0 Thanks and Regards, Hariharan C
It always goes based on the first key you pressed, there are probably custom controls out there that do what you want, but the standard one, does not
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi all, There is a small requirement in drop down list. Suppose I have bounded the employee names to the drop down list. Now I am searching for a name “Peter”. So if I press ‘p’ and then ‘e’ it should go to Peter’s name. But it goes to Elizabeth’s name. Is there any solution for that? Could anyone of you please help me on that? I am using .Net version 2.0 Thanks and Regards, Hariharan C
I suggest you to use Ajax AutoComplete (something like Google suggest) instead of using dropdown list. eg: Creating a Textbox with JavaScript Auto-Complete[^] http://www.codeproject.com/aspnet/AJAXWasHere-Part3.asp[^]
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
It always goes based on the first key you pressed, there are probably custom controls out there that do what you want, but the standard one, does not
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I suggest you to use Ajax AutoComplete (something like Google suggest) instead of using dropdown list. eg: Creating a Textbox with JavaScript Auto-Complete[^] http://www.codeproject.com/aspnet/AJAXWasHere-Part3.asp[^]
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Michael, I know there is a solution in Ajax. But if i select Ajax, then i will find difficult to implement in my project. So is there any solution without using Ajax. Thanks and Regards, Hariharan C
AJAX is just javascript. The odds of there being a non js solution are close to zero.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi Michael, I know there is a solution in Ajax. But if i select Ajax, then i will find difficult to implement in my project. So is there any solution without using Ajax. Thanks and Regards, Hariharan C
Have you tested in Firefox (latest version)? It works well as the way you want without changing anything. but it doesn't work in IE6. I'm looking for the solution for you.. I will let you know once done.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Have you tested in Firefox (latest version)? It works well as the way you want without changing anything. but it doesn't work in IE6. I'm looking for the solution for you.. I will let you know once done.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Have you tested in Firefox (latest version)? It works well as the way you want without changing anything. but it doesn't work in IE6. I'm looking for the solution for you.. I will let you know once done.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Michael, Yes its working fine in firefox. But its there any other way to make it work in IE. If you got the solution let me know it. Thanks and Regards, Hariharan C
Hello Hariharan, I just arrive at home and I remember your question that I don't have enough time to figure out the solution.. So, I opened my page and I'm trying to reproduce this issue. Now, I have tested with Internet Explorer 7, Firefox 2.0.0.6, Opera 9.2 and Safari 3.0.3. It is working fine in all those browsers except internet explorer 6. I don't have this one in my laptop. I tried to install IE6 standalone version that can run with IE7 on same machine but that installer doesn't work on Windows Vista. :( Anyway, I'm gonna give you some codes that I think it should work on IE6.
var pressedKeyString = ""; var delay = 1000; var timeID = null; function move(id){ var selectList = document.getElementById(id); var arr = new Array(); var idx = 0; for(var i = 0; i < selectList.options.length-1; i++){ if(selectList.options[i].value.length >= pressedKeyString.length){ if(pressedKeyString.toLowerCase() == selectList.options[i].value.substring(0,pressedKeyString.length).toLowerCase()){ selectList.options[i].select = true; i=selectList.options.length; } } } //pressedKeyString = ""; } function foo(e,id){ if(timeID != null)clearTimeout(timeID); timeID = setTimeout("move('" + id + "');",delay); var key; if(window.event) // IE { key = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { key = e.which } var pressKey = String.fromCharCode(key); pressedKeyString += pressKey; }
protected void Page_Load(object sender, EventArgs e) { DropDownList1.Attributes.Add("onkeypress", "foo(event,'" + DropDownList1.ClientID + "');"); List list = new List(); list.Add("Alien"); list.Add("Emos"); list.Add("Poker"); list.Add("Peter"); list.Add("Michael Sync"); list.Add("Petro"); list.Add("Pet"); list.Add("Elizabeth"); DropDownList1.DataSource = list; DropDownList1.DataBind(); }
The main -
Hello Hariharan, I just arrive at home and I remember your question that I don't have enough time to figure out the solution.. So, I opened my page and I'm trying to reproduce this issue. Now, I have tested with Internet Explorer 7, Firefox 2.0.0.6, Opera 9.2 and Safari 3.0.3. It is working fine in all those browsers except internet explorer 6. I don't have this one in my laptop. I tried to install IE6 standalone version that can run with IE7 on same machine but that installer doesn't work on Windows Vista. :( Anyway, I'm gonna give you some codes that I think it should work on IE6.
var pressedKeyString = ""; var delay = 1000; var timeID = null; function move(id){ var selectList = document.getElementById(id); var arr = new Array(); var idx = 0; for(var i = 0; i < selectList.options.length-1; i++){ if(selectList.options[i].value.length >= pressedKeyString.length){ if(pressedKeyString.toLowerCase() == selectList.options[i].value.substring(0,pressedKeyString.length).toLowerCase()){ selectList.options[i].select = true; i=selectList.options.length; } } } //pressedKeyString = ""; } function foo(e,id){ if(timeID != null)clearTimeout(timeID); timeID = setTimeout("move('" + id + "');",delay); var key; if(window.event) // IE { key = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { key = e.which } var pressKey = String.fromCharCode(key); pressedKeyString += pressKey; }
protected void Page_Load(object sender, EventArgs e) { DropDownList1.Attributes.Add("onkeypress", "foo(event,'" + DropDownList1.ClientID + "');"); List list = new List(); list.Add("Alien"); list.Add("Emos"); list.Add("Poker"); list.Add("Peter"); list.Add("Michael Sync"); list.Add("Petro"); list.Add("Pet"); list.Add("Elizabeth"); DropDownList1.DataSource = list; DropDownList1.DataBind(); }
The main -
Hello Hariharan, I just arrive at home and I remember your question that I don't have enough time to figure out the solution.. So, I opened my page and I'm trying to reproduce this issue. Now, I have tested with Internet Explorer 7, Firefox 2.0.0.6, Opera 9.2 and Safari 3.0.3. It is working fine in all those browsers except internet explorer 6. I don't have this one in my laptop. I tried to install IE6 standalone version that can run with IE7 on same machine but that installer doesn't work on Windows Vista. :( Anyway, I'm gonna give you some codes that I think it should work on IE6.
var pressedKeyString = ""; var delay = 1000; var timeID = null; function move(id){ var selectList = document.getElementById(id); var arr = new Array(); var idx = 0; for(var i = 0; i < selectList.options.length-1; i++){ if(selectList.options[i].value.length >= pressedKeyString.length){ if(pressedKeyString.toLowerCase() == selectList.options[i].value.substring(0,pressedKeyString.length).toLowerCase()){ selectList.options[i].select = true; i=selectList.options.length; } } } //pressedKeyString = ""; } function foo(e,id){ if(timeID != null)clearTimeout(timeID); timeID = setTimeout("move('" + id + "');",delay); var key; if(window.event) // IE { key = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { key = e.which } var pressKey = String.fromCharCode(key); pressedKeyString += pressKey; }
protected void Page_Load(object sender, EventArgs e) { DropDownList1.Attributes.Add("onkeypress", "foo(event,'" + DropDownList1.ClientID + "');"); List list = new List(); list.Add("Alien"); list.Add("Emos"); list.Add("Poker"); list.Add("Peter"); list.Add("Michael Sync"); list.Add("Petro"); list.Add("Pet"); list.Add("Elizabeth"); DropDownList1.DataSource = list; DropDownList1.DataBind(); }
The main -
Hi Michael, Have you got the solution for me. I am not able to get it. So if you got the solution let me know please. Thanks and Regards, Hariharan C
Hello Hariharan, Sorry for late reply. Yesterday was a holiday (Birthday of S'pore[^]) I have tested my code that I gave you earlier. There is only thing that we need to change in my code. We should use selectedIndex
selectList.selectedIndex = 2;
instead ofselectList.options[i].select = true;
The completed code is as below ~var pressedKeyString = ""; var delay = 1000; var timeID = null; function move(){ var selectList = document.getElementById('DropDownList1'); var arr = new Array(); var idx = 0; for(var i = 0; i < selectList.options.length-1; i++){ if(selectList.options[i].value.length >= pressedKeyString.length){ if(pressedKeyString.toLowerCase() == selectList.options[i].value.substring(0,pressedKeyString.length).toLowerCase()){ <b> selectList.selectedIndex = i;</b> i=selectList.options.length; alert(pressedKeyString); } } } pressedKeyString = ""; } function foo(e,id){ if(timeID != null)clearTimeout(timeID); timeID = setTimeout("move();",delay); var key; if(window.event) // IE { key = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { key = e.which } var pressKey = String.fromCharCode(key); pressedKeyString += pressKey; }
Note that "onkeypress
" event is a javascript event (not server-side event). As I mentioned my idea, the character that you typed will keep on appending to the string called pressedKeyString. (while you are typing, the select list will be changed by default. (this is what we don't want)). After finished typing (timer will count to 1000 minisecound), then the dropdown list will be changed to the option which is matched with the characters that you enter. (eg: if you type "pe" then dropd -
Hello Hariharan, Sorry for late reply. Yesterday was a holiday (Birthday of S'pore[^]) I have tested my code that I gave you earlier. There is only thing that we need to change in my code. We should use selectedIndex
selectList.selectedIndex = 2;
instead ofselectList.options[i].select = true;
The completed code is as below ~var pressedKeyString = ""; var delay = 1000; var timeID = null; function move(){ var selectList = document.getElementById('DropDownList1'); var arr = new Array(); var idx = 0; for(var i = 0; i < selectList.options.length-1; i++){ if(selectList.options[i].value.length >= pressedKeyString.length){ if(pressedKeyString.toLowerCase() == selectList.options[i].value.substring(0,pressedKeyString.length).toLowerCase()){ <b> selectList.selectedIndex = i;</b> i=selectList.options.length; alert(pressedKeyString); } } } pressedKeyString = ""; } function foo(e,id){ if(timeID != null)clearTimeout(timeID); timeID = setTimeout("move();",delay); var key; if(window.event) // IE { key = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { key = e.which } var pressKey = String.fromCharCode(key); pressedKeyString += pressKey; }
Note that "onkeypress
" event is a javascript event (not server-side event). As I mentioned my idea, the character that you typed will keep on appending to the string called pressedKeyString. (while you are typing, the select list will be changed by default. (this is what we don't want)). After finished typing (timer will count to 1000 minisecound), then the dropdown list will be changed to the option which is matched with the characters that you enter. (eg: if you type "pe" then dropdHi Michael, Ya its working fine for me. Thanks a lot for your kind help. But again there is one small problem. When i type 'pe' it goes to 'Peter'. After that when i do it for the second time, its not working.(i.e After i typed 'pe', I wait for 1000 ms for the dropdownlist to select 'peter'. That's fine. Then I typed 'Ki', the dropdownlist has not select the name 'Kiran'. It selects "Indhu"). Have you checked that. If you know the answer let me know. Else again thanks a lot for your kind help. Thanks and Regards, Hariharan C
-
Hi Michael, Ya its working fine for me. Thanks a lot for your kind help. But again there is one small problem. When i type 'pe' it goes to 'Peter'. After that when i do it for the second time, its not working.(i.e After i typed 'pe', I wait for 1000 ms for the dropdownlist to select 'peter'. That's fine. Then I typed 'Ki', the dropdownlist has not select the name 'Kiran'. It selects "Indhu"). Have you checked that. If you know the answer let me know. Else again thanks a lot for your kind help. Thanks and Regards, Hariharan C
I have tried that. It works.
Hari_1010 wrote:
(i.e After i typed 'pe', I wait for 1000 ms for the dropdownlist to select 'peter'. That's fine. Then I typed 'Ki', the dropdownlist has not select the name 'Kiran'. It selects "Indhu").
Did you wait for 1000 ms after typing 'Ki'? I have tested with the following data..
DropDownList1.Attributes.Add("onkeypress", "foo(event,'" + DropDownList1.ClientID + "');"); List list = new List(); list.Add("Alien"); list.Add("Emos"); list.Add("Emos2"); list.Add("Poker"); list.Add("Peter"); list.Add("Michael Sync"); list.Add("Petro"); list.Add("Pet"); list.Add("Elizabeth"); list.Add("Kiran"); list.Add("Kate BackInSales"); DropDownList1.DataSource = list; DropDownList1.DataBind()
I tried three times. ('Pe', 'Ki', 'Em'). It works fine.. Please try it again and let me know.. Note: you have to wait 1000 ms every time after typing something...Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
I have tried that. It works.
Hari_1010 wrote:
(i.e After i typed 'pe', I wait for 1000 ms for the dropdownlist to select 'peter'. That's fine. Then I typed 'Ki', the dropdownlist has not select the name 'Kiran'. It selects "Indhu").
Did you wait for 1000 ms after typing 'Ki'? I have tested with the following data..
DropDownList1.Attributes.Add("onkeypress", "foo(event,'" + DropDownList1.ClientID + "');"); List list = new List(); list.Add("Alien"); list.Add("Emos"); list.Add("Emos2"); list.Add("Poker"); list.Add("Peter"); list.Add("Michael Sync"); list.Add("Petro"); list.Add("Pet"); list.Add("Elizabeth"); list.Add("Kiran"); list.Add("Kate BackInSales"); DropDownList1.DataSource = list; DropDownList1.DataBind()
I tried three times. ('Pe', 'Ki', 'Em'). It works fine.. Please try it again and let me know.. Note: you have to wait 1000 ms every time after typing something...Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Michael, I checked it again. For me its working fine for the first time only. Anyway Michael thanks a lot for your help. Thanks and Regards, Hariharan C
Hi Hariharan, I think that you didn't check the code that I give you second time. I have uncommented the
pressedString = "";
in move function.. You may also check this ASP.NET: DropDown List problem with IE6[^]Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Hariharan, I think that you didn't check the code that I give you second time. I have uncommented the
pressedString = "";
in move function.. You may also check this ASP.NET: DropDown List problem with IE6[^]Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Hariharan, I think that you didn't check the code that I give you second time. I have uncommented the
pressedString = "";
in move function.. You may also check this ASP.NET: DropDown List problem with IE6[^]Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Hi Michael, Now I have added one more dropdownlist and bound to the object data source(says Employee name). Then I tried to call your script, where its not working. Can you please tell me what I have to do now. Thanks and Regards, Hariharan C
Hi Hariharan, It's good to hear that. If my script works for you, don't forget to vote my message. :) thanks. Instead of using static name "DropDownList1", you should probably pass this name as the parameter. so, it will work if you have more than one dropdown.
var selectList = document.getElementById('DropDownList1');
This variable holds only one value. maybe. you can add more variables. or you can handle this variable to hold the value depend on what the user is typing.var pressedKeyString = "";
Hope it helps.Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)