Go to DotNetFunda.com
 Welcome, Guest!  
LoginLogin  
{ Submit content and get exposure !!! }
Submit: Article | Interview Question | Tips | Joke | Question | Link || Search  
 Skip Navigation Links Home > Articles > ToolTip for List Items

All Articles | Post Articles |  Subscribe to RSS

ToolTip for List Items

 Posted on: 7/24/2008 4:16:14 AM by Deeraj | Views: 626 | Category: ASP.NET | Level: Intermediate | Print Article
ASP.NET Hosting with Windows 2008/2003
Adding tooltips for Items in a dropdownlist control


Introduction

At times dropdownlists will contain data of more than anticipated length. However, no one prefers having dropdownlists which are very wide. Also, the 'ToolTipText' property of the dropdownlist will provide tooltip for the entire control. Meaning, TooTip is available only for the current selected item in the dropdownlist. But, requirement says that the tooltip should be available for each item in the dropdownlist.

Details

Here is a small tip thats pretty handy.

The AddToolTip is a generic routine that will accept an object of type dropdownlist. It would then inject javascript by making use of the 'title' attribute. The title attribute will be added to each of the items present in the object under discussion.

NOTE: This tip is applicable to IE 7.0 and later versions.

Implementation:

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                FillDropDownList(bErrors); //Bind the dropdownlists.
            }
            AddToolTip(serverdropdownlist);
        }
        private void AddToolTip(DropDownList lst)
        {
            foreach (ListItem curItem in lst.Items)
            {
                curItem.Attributes.Add("title", curItem.Text);
            }
        }

Output:



Conclusion

Happy programming... :)


Interesting?  Bookmark and Share kick it on DotNetKicks.com


Experience:4 year(s)
Home page:
Member since:Monday, October 29, 2007
Biography:
 Latest post(s) from Deeraj

   ◘ Recursive FTP folder deletes in .NET 2.0 posted on 8/26/2008 2:16:16 PM
   ◘ Generating XML from relational database tables posted on 8/4/2008 8:25:14 AM
   ◘ ToolTip for List Items posted on 7/24/2008 4:16:14 AM
   ◘ Debugging Stored Procedures in SQL Server 2005 posted on 11/12/2007 6:56:44 AM
   ◘ Tracking Object (Table/Function/Stored Procedure etc.,) changes in SQL Server 2005 posted on 11/7/2007 5:53:44 AM




About Us | Contact Us | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)