Web Analytics Made Easy -
StatCounter DropDownList as Combo Box - Possible? - CodingForum

Announcement

Collapse
No announcement yet.

DropDownList as Combo Box - Possible?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DropDownList as Combo Box - Possible?

    Hi,

    I have a long list in a DropDownList, instead of the user having the tedious task of scrolling through and finding the right one - is it possible to type all or part of the text of the item in the list and have ASP.NET to automatically jump to the nearest match in the list?

    Thanks.

  • #2
    You'll need some custom client-side JavaScript to achieve that (unless someone's written a .Net web control that encapsulates the functionality)...

    You could get some ideas from the way this works:
    http://www.somacon.com/phpref/

    And this is another way of doing it:
    http://www.mattkruse.com/javascript/autocomplete/
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

    Comment


    • #3
      I've written a PHP filter-search-sort class last week that amongst other things generates dropdowns from a recordset.

      One of the features is an automatic conversion into a searchbox.
      It's quite simple. When you build the dropdown, you check the number of unique option-values. If these exceed a certain limit, you display a searchbox. When he types in a value, the searchvalue is used inside a select to get all matching records, and if there are less then 50 or whatever limit you set, a dropdown is build with all labels that contain the searchvalue.

      I didn't use javascript because i wanted a universal, completely serversided sollution.

      I sadly don't have time right now to make an ASP version of the class, but it shouldn't be that hard to do it yourself.
      Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

      Comment


      • #4
        Javascript version

        See the Editable Type-ahead combo script in my sig.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Thanks for your help, people. I am going to look at the javascript code for those combo boxes and see of this can be used with an asp.net dropdownlist. Most server controls can have extra functionality added to them by using the attributes.add method to assign events like onclick or mouseover, etc.

          See this article here.

          http://aspnet.4guysfromrolla.com/articles/021104-1.aspx


          So it is possible to apply an onkeypress event to an asp.net DropDownList and call a java script function.

          The question I have is how do you access ASP.NET Server Controls from within a client Javascript function? Has anyone tried this? I am developing a timesheet database using asp.net for a client and I want to do the calculations and totals plus updating certain text fields without having to do a post back and refreshing the page.

          All the dropdown list and textboxes are asp.net server controls.

          Comment


          • #6
            I'm not yet a .NET coder but I have a little knowledge in .NET principles.

            ASP.NET server controls are of course, server controls. But the server generates the corresponding client-side control (html) including its attributes and event handlers (onclick, onmouseover, etc) depending on the settings you've done on the server control. So when the control is rendered in the browser, it is now an html control (client-side) not server control. So those event handlers attached to the control such as onclick will be executed by the client control not the server control. I think you only need to make AutoPostback=False in the server control so that form submission is not triggered.

            To clearly understand this, view the source of the html when the page is rendered to see the generated client controls of the server controls.
            Glenn
            vBulletin Mods That Rock!

            Comment

            Working...
            X