Page view counter

How to add a tooltip to a dropdownlist?

Last post 12-17-2008 11:12 AM by seebRnet. 16 replies.

Sort Posts:

  • How to add a tooltip to a dropdownlist?

    07-21-2005, 7:05 AM
    • Loading...
    • haris101
    • Joined on 07-09-2005, 9:19 AM
    • Indonesia
    • Posts 180
    • Points 266
    How to add a tooltip to a dropdownlist?

    Why declaring it in the dropdownlist tag...
    <asp:dropdownlist tooltip=.../>
    ...doesn't work?

    I also have tried to declare it in my codebehind...
    dropSomething.tooltip = "..."
    ... but nothing happens.
  • Re: How to add a tooltip to a dropdownlist?

    07-21-2005, 8:50 AM
    • Loading...
    • vijay_it
    • Joined on 09-08-2004, 12:16 AM
    • India
    • Posts 40
    • Points 200

    Unfortunately you can not have tool tip on a drop down, but there is work around

    U make a div and put dropdown inside the div, give the title property of the div to whatever text you want to display

    The quality of our thinking will determine the quality of our future
  • Re: How to add a tooltip to a dropdownlist?

    07-21-2005, 8:54 AM
    • Loading...
    • XIII
    • Joined on 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 12,638
    • Points 109,610
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
    Hi,

    that's quite normal because the rendered html is a <select> which doesn't contain a property for setting tooltips.

    Grz, Kris.
  • Re: How to add a tooltip to a dropdownlist?

    07-21-2005, 8:58 AM
    • Loading...
    • DarrellNorton
    • Joined on 04-04-2003, 3:49 PM
    • VA, USA
    • Posts 6,114
    • Points 48,247
    • Moderator
    No, the DropDownList does not have a ToolTip property. The way to achieve this functionality is to add a "title" attribute to the control:

    myDropDownList.Attributes.Add("title","This is my tooltip.")
    or
    myDropDownList.Attributes("title") = "This is my tooltip."
    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
  • Re: How to add a tooltip to a dropdownlist?

    07-21-2005, 12:17 PM
    Answer
    • Loading...
    • PLBlum
    • Joined on 06-28-2002, 1:20 PM
    • Boston, MA
    • Posts 5,308
    • Points 30,007
    • TrustedFriends-MVPs
    There is a lot of confusion about tooltips on DropDownLists. Here's the facts.

    IE for Windows does not support the Tooltip property or even the title attribute on the <select> control. This is because they create a separate window for the <select> tag that is above the rest of the info on the browser window. (Think of it as another layer.) The tooltip engine is actually on the main window layer, so the tooltip would appear behind the <select> element if it was to appear. This layered behavior also breaks popups that position over <select> tags because they are always on the main window layer!

    The title= attribute is fully supported in the W3C specification, which is used by the DOM-based browsers like Mozilla, FireFox, Netscape, and Safari. So by assigning myDropDownList.Attributes.Add("title", "text"), you will get a tooltip on those browsers!

    Finally, the suggestion to enclose the DropDownList in the <div> with a title= attribute will only work so long as the user does not point to the <select> element itself because of the layering problem.

    We can only hope Microsoft puts <select> tags into the same layer in a future version of IE...
    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: How to add a tooltip to a dropdownlist?

    09-27-2007, 9:04 AM
    • Loading...
    • monalijaju
    • Joined on 09-27-2007, 12:53 PM
    • Posts 1
    • Points 2

     

    Even after adding the dropdownlist in <div> dint solve the problem. I wonder how to do this.

    Is there any property of the drop-down so that the width of drop-downlist automatically gets increased. Or can the right scoll bar be added to the drop-down-list?

  • Re: How to add a tooltip to a dropdownlist?

    10-19-2007, 7:50 AM
    • Loading...
    • gb_eh
    • Joined on 08-28-2007, 6:34 PM
    • Posts 10
    • Points 2

     Peter's (PLBlum) explains the problem perfectly... I use labels for each of my listbox / droplist and I've put the tooltip behind the label instead of the control, again not pretty or perfect but better than nothing.

  • Re: How to add a tooltip to a dropdownlist?

    03-25-2008, 10:06 AM
    • Loading...
    • AhmedHussein
    • Joined on 11-16-2006, 1:08 PM
    • Posts 2
    • Points 4

    The strange behavior is: If you add disabled="disabled" to select tag the title text  will appear ???? :D 

    Anyway: This problem solved in IE 7.0.

  • Re: How to add a tooltip to a dropdownlist?

    05-31-2008, 2:17 PM
    • Loading...
    • bilsoft
    • Joined on 05-28-2008, 7:10 AM
    • Posts 6
    • Points 4

    the above code is working fine in firefox but not in ie6 :( is there any way to short it out???

  • Re: How to add a tooltip to a dropdownlist?

    06-07-2008, 6:22 AM
    • Loading...
    • muralithangaraj
    • Joined on 04-14-2008, 9:22 AM
    • Mumbai
    • Posts 29
    • Points 148

                 ddlToolTip.Items.Add("Item First");
                ddlToolTip.Items[0].Attributes.Add("title", "Tool Tip");

                ddlToolTip.Items.Add("Item Second");
                ddlToolTip.Items[1].Attributes.Add("title", "Second Item Tool Tip"); 

     

    We can give tool tip by this way also....   The only thing is i did not not check in all browser. but it is working in firefox2.0

     

     

    By
    Murali Thangaraj

    If this is Answers your Question Click "MARK AS ANSWERED".
  • Re: How to add a tooltip to a dropdownlist?

    06-18-2008, 8:37 AM
    • Loading...
    • yasserzaid
    • Joined on 09-22-2007, 9:10 PM
    • Egypt
    • Posts 2,531
    • Points 15,311

    Hi

    tryt his:

     

    <form id="Form1" method="post" runat="server">
     <asp:DropDownList id="DropDownList1" onmouseover="showDropDownToolTip(this);" onmouseout="hideDropDownToolTip();" runat="server">
      <asp:listitem value="">Select One</asp:listitem>
      <asp:listitem value="Images/Image1.gif">Image1</asp:listitem>
      <asp:listitem value="Images/Image2.gif">Image2</asp:listitem>
      <asp:listitem value="Images/Image3.gif">Image3</asp:listitem>
     </asp:DropDownList>
    
     <div id="divDropDownToolTip" style="position:absolute;display:none;background:lightyellow;border:1px solid gray;padding:2px;font-size:8pt;font-family:Verdana;" onMouseOut="hideDropDownToolTip()">
      <img id="informationImage" src="" border="0"/>
      <span id="informationText"></span>
     </div>
    </form>
    
    <script type="text/javascript">
    <!--
    function showDropDownToolTip(elementRef) 
    {
     if ( elementRef.options[elementRef.selectedIndex].value == '' )
      return;
    
     // Set to some new image...
     var imageRef = document.getElementById('informationImage');
     imageRef.src = elementRef.options[elementRef.selectedIndex].value;
    
     // Set to information text...
     var informationSpanRef = document.getElementById('informationText');
     informationSpanRef.innerHTML = elementRef.options[elementRef.selectedIndex].text;
    
     var toolTipRef = document.getElementById('divDropDownToolTip');
     toolTipRef.style.top = window.event.clientY + 20;
     toolTipRef.style.left = window.event.clientX;
     toolTipRef.style.display = 'block';
    }
    
    function hideDropDownToolTip()
    {
     document.getElementById('divDropDownToolTip').style.display = 'none';
    }
    // -->
    </script>
    
    
    
    
     
  • Re: How to add a tooltip to a dropdownlist?

    10-29-2008, 1:46 PM
    • Loading...
    • AdventurGurl
    • Joined on 10-29-2008, 5:43 PM
    • Posts 1
    • Points 2

    Hi,

    Add  a ondatabound="ApplyOptionTitles" event to your DropDownList control.

    Then implement in code-behind (C#) as follows: 

    protected void ApplyOptionTitles(object sender, EventArgs e)
    {
       DropDownList ddl = sender as DropDownList;
       if (ddl != null)
       {
            foreach (ListItem item in ddl.Items)
            {
               item.Attributes["title"] = item.Text;
             }
        }
    }

  • Re: How to add a tooltip to a dropdownlist?

    12-04-2008, 8:22 AM
    • Loading...
    • seebRnet
    • Joined on 12-04-2008, 8:18 AM
    • Posts 2
    • Points 4

    AdventurGurl:

    Hi,

    Add  a ondatabound="ApplyOptionTitles" event to your DropDownList control.

    Then implement in code-behind (C#) as follows: 

    protected void ApplyOptionTitles(object sender, EventArgs e)
    {
       DropDownList ddl = sender as DropDownList;
       if (ddl != null)
       {
            foreach (ListItem item in ddl.Items)
            {
               item.Attributes["title"] = item.Text;
             }
        }
    }



    This solution works great! Thanks!

    And more : Implement this method only into a class BasePage (which inherits from System.Web.UI.Page) that every web page of your application inherits and link all your DropDownList DataBound events to this method (OnDataBound="ApplyOptionTitles"). You will have only one method for all your DropDownLists of your application.

  • How to add a tooltip to a dropdownlist? - Reply ASAP, Pls.

    12-15-2008, 3:05 PM
    • Loading...
    • shan1901
    • Joined on 12-15-2008, 8:01 PM
    • Posts 4
    • Points 4

    Hi,

     I tried this & not working for me. I am using IE 6.0, framework 3.5, VS2008. Can you let me know what is the prob? I am new.

     

  • Re: How to add a tooltip to a dropdownlist? - Reply ASAP, Pls.

    12-16-2008, 2:15 AM
    • Loading...
    • sirmansoor
    • Joined on 05-17-2007, 7:44 AM
    • Posts 3
    • Points 6

    IE 6 does not support "title" attribute.

Page 1 of 2 (17 items) 1 2 Next >