Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Requirement in Drop down list

Requirement in Drop down list

Scheduled Pinned Locked Moved ASP.NET
csharpalgorithmshelpquestionannouncement
21 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Michael Sync

    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. :)

    H Offline
    H Offline
    Hari_1010
    wrote on last edited by
    #9

    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

    M 1 Reply Last reply
    0
    • H Hari_1010

      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

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #10

      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

      H 2 Replies Last reply
      0
      • M Michael Sync

        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

        H Offline
        H Offline
        Hari_1010
        wrote on last edited by
        #11

        Hi Michael, I have checked your code, its not working in IE6. There is a small doubt, is there 'onkeypress' event for Dropdownlist. Thanks and Regards, Hariharan C

        1 Reply Last reply
        0
        • M Michael Sync

          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

          H Offline
          H Offline
          Hari_1010
          wrote on last edited by
          #12

          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

          M 1 Reply Last reply
          0
          • H Hari_1010

            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

            M Offline
            M Offline
            Michael Sync
            wrote on last edited by
            #13

            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 of selectList.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

            H 1 Reply Last reply
            0
            • M Michael Sync

              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 of selectList.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

              H Offline
              H Offline
              Hari_1010
              wrote on last edited by
              #14

              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

              M 1 Reply Last reply
              0
              • H Hari_1010

                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

                M Offline
                M Offline
                Michael Sync
                wrote on last edited by
                #15

                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. :)

                H 1 Reply Last reply
                0
                • M Michael Sync

                  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. :)

                  H Offline
                  H Offline
                  Hari_1010
                  wrote on last edited by
                  #16

                  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

                  M 1 Reply Last reply
                  0
                  • H Hari_1010

                    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

                    M Offline
                    M Offline
                    Michael Sync
                    wrote on last edited by
                    #17

                    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. :)

                    H 2 Replies Last reply
                    0
                    • M Michael Sync

                      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. :)

                      H Offline
                      H Offline
                      Hari_1010
                      wrote on last edited by
                      #18

                      Hi Michael, Very good morning. I just saw your reply after the weekend. You are correct. Yes i forget to uncomment the code. Now its working fine. Thanks a lot man. This is going to be very useful for me. Thanks and Regards, Hariharan

                      1 Reply Last reply
                      0
                      • M Michael Sync

                        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. :)

                        H Offline
                        H Offline
                        Hari_1010
                        wrote on last edited by
                        #19

                        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

                        M 1 Reply Last reply
                        0
                        • H Hari_1010

                          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

                          M Offline
                          M Offline
                          Michael Sync
                          wrote on last edited by
                          #20

                          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. :)

                          H 1 Reply Last reply
                          0
                          • M Michael Sync

                            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. :)

                            H Offline
                            H Offline
                            Hari_1010
                            wrote on last edited by
                            #21

                            Hi Michael, In the function "foo(event,id)", can you tell me what is the use of the event. See in my website I got this dropdown list in a formview insert template where it bound to the object data source. I have added your script to my master page. And the function calling is as follows, protected void FormView1_DataBound(object sender, EventArgs e) { switch (FormView1.CurrentMode) { case FormViewMode.Insert: ((DropDownList)FormView1.FindControl("DropDownList3")).Attributes.Add ("onkeypress", "javascript:return foo(event,'ctl00_ContentPlaceHolder1_FormView1_DropDownList3');"); break; } } But its not working in my page. So can you please help me on this. Dont worry Michael defenitely i am going to vote for you. Thanks in advance. Thanks and Regards, Hariharan C

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups