Showing posts with label dropdown tooltip. Show all posts
Showing posts with label dropdown tooltip. Show all posts

25 January 2012

Tooltip for dropdownlist items

It is common in most web pages that whole text in dropdown lists cannot be seen due to width limitation. One solution for this would be adding tooltip for the dropdown, so that when selecting a value from dropdown, whole text will be appear as a tooltip. For most of browsers implementing tooltip on dropdown control is not a big deal. We can simply add tooltip text with 'title' attribute. C# implementation for this would be as follows

public void SetToolTip(DropDownList ddl)
{
    if (ddl.Items.Count > 0)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("Title", item.Text);
        }
    }
}