• Sign In
 
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...
Common Tasks
  • Blog Home
  • Email Blog Author
  • RSS for comments
  • RSS for posts
Search
  • Advanced search options...
Tags
  • .NET Framewor
  • .NET Framework
  • Ajax/Javascript
  • ASP.NET
  • CLR
  • Cool stuff
  • DataAccess
  • Debugging/Windbg
  • Hotfix/Service Pack
  • IDEVDataCollector
  • IIS
  • Internet Explorer
  • Italian techs
  • LogParser
  • OT
  • Personal
  • Productivity
  • Random
  • Scripting/ASP
  • Security
  • Technology
  • Tools
  • Troubleshooting
  • Vista/Longhorn
  • Visual Studio
Archives
Archives
  • November 2010 (1)
  • October 2010 (1)
  • July 2010 (2)
  • April 2010 (1)
  • March 2010 (2)
  • February 2010 (2)
  • January 2010 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (1)
  • July 2009 (5)
  • June 2009 (1)
  • May 2009 (1)
  • April 2009 (3)
  • March 2009 (3)
  • February 2009 (5)
  • January 2009 (3)
  • December 2008 (5)
  • November 2008 (3)
  • October 2008 (2)
  • September 2008 (3)
  • August 2008 (3)
  • July 2008 (3)
  • June 2008 (5)
  • May 2008 (4)
  • April 2008 (8)
  • March 2008 (4)
  • February 2008 (5)
  • January 2008 (2)
  • December 2007 (4)
  • November 2007 (6)
  • October 2007 (6)
  • September 2007 (8)
  • August 2007 (6)
  • July 2007 (7)
  • June 2007 (10)
  • May 2007 (9)
  • April 2007 (12)
  • March 2007 (8)
  • February 2007 (5)
  • January 2007 (3)
  • December 2006 (1)
  • November 2006 (4)
  • October 2006 (2)
  • September 2006 (9)
  • August 2006 (2)
  • July 2006 (1)

DropDownList with tooltip

MSDN Blogs > Never doubt thy debugger > DropDownList with tooltip

DropDownList with tooltip

Carlo Cardella
26 Sep 2008 3:35 AM
  • Comments 6

I recently got this question from a customer whom is binding some data to a DropDownList control inside a GridView; the various items inside the DropDownList has variable length while the control itself per their page resign requirements must be fixed, making it difficult to fully read and understand the text associated with the selected item, so the customer asked for some hints to add a tooptip functionality to the DropDownList. Before raising the call he had already searched the Internet but without much luck; I did the same myself and apparently there are plenty of samples showing how to display a tooltip when the mouse is over an item already selected in a DropDown control, but the customer wanted something different: he needed to show the tooltip over each item in the DropDownList before actually selecting them to help users make the appropriate selection.

Well, for Internet Explorer 7 (al later) it is possible to use the “Title” attribute for the <option> tag:

for (int i = 0; i < GridView1.Rows.Count; i++)
{
    //Add logic to fill the GridView

    //Now let's iterate through the DropDown controls to add a "Title" to the
    //resulting HTML "<option>" elements: this will add the toolip to highlighted element
    for (int i2 = 0; i2 < dropDownList.Items.Count; i2++)
    {
        dropDownList.Items[i2].Attributes.Add("Title", dropDownList.Items[i2].Text);
    }
}

 

Here is how it looks like in IE7:

tooltip in IE7

 

Even if Firefox (at least the version I’ve tried) does not respect the control width we have set through CSS and the DropDown for this sample is large enough to read the complete text, the tooltip is displayed:

tooltip in Firefox

 

Unfortunately this is not supported by previous versions if IE, though… if anyone has a suggestion, feel free to add a comment! smile_nerd

 

Carlo

Quote of the day:
Calamities are of two kinds: misfortunes to ourselves, and good fortune to others. - Ambrose Bierce
  • 6 Comments
ASP.NET, Internet Explorer
Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
Comments
  • Yahoo
    3 Nov 2008 2:07 AM

    Your article help me so much.

    I use property called "title" in HTML

    <select>

    <option value = \"Test data"+"\" title = \"Test DATA NEW Version value show1"+"\"" + "selected" + ">" + "Test DATA NEW Version1"+ "</option>

    </select>

    it can display like your example.

  • am
    26 Nov 2008 1:40 AM

    hi... carlo,

    i used ur code, but its not working.

    i m using IE 8 beta. :(

  • Rakesh
    7 Jan 2009 11:49 PM

    <select>

    <option value = \"Test data"+"\" title = \"Test DATA NEW Version value show1"+"\"" + "selected" + ">" + "Test DATA NEW Version1"+ "</option>

    </select>

    Tooltip in this control will event not working IE6 i tried this.

  • santosh
    8 Jun 2009 2:19 AM

    Please tell me how to make it work in IE6

  • Carlo Cardella
    8 Jun 2009 3:13 AM

    Santosh, unfortunately it does not work on IE6, it does not support the "Title" attribute, sorry...

  • Shaip
    13 Feb 2010 3:02 AM

    Your code is helpful, thanks...

Page 1 of 1 (6 items)
  • © 2012 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy Statement
  • Report Abuse
  • 5.6.402.223