ToolTip for List Items

Posted by in ASP.NET category on for Intermediate level | Views : 13347 red flag

Adding tooltips for Items in a dropdownlist control

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.


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.


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



Happy programming... :)

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Deeraj Chakravarthy
Member Level: Starter
Member Status: Member
Member Since: 10/29/2007 1:00:04 AM
Country: India

Qualification: BCA, MScIS, MDSE, PMI-ACP

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)