Go to DotNetFunda.com
 Online : 1361 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > ToolTip for List Items

Submit Article | Articles Home | Search Articles |

ToolTip for List Items

red flag  Posted on: 7/24/2008 4:16:14 AM by Deeraj | Views: 3462 | Category: ASP.NET | Level: Intermediate


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


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Found interesting? Add this to:

| More



Please Sign In to vote for this post.

 
Latest post(s) from Deeraj

Latest Articles
Experience:5 year(s)
Home page:
Member since:Monday, October 29, 2007
Level:Starter
Status: [Member]
Biography:Qualification: BCA, MScIS, MDCA

Submit Article

About Us | The Team | Advertise | Contact Us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 9/7/2010 12:46:10 AM