Displaying tooltip for Dropdownlist items.

Ndebata
Posted by Ndebata under ASP.NET category on | Points: 40 | Views : 4739
The list items in a drop down list does not have a tool tip property and many time dues to space constraint we need to specify the width of a drop down and some items have text length greater than the width. In this case we can show a tooltip for that item displaying its text property as a tooltip.

I have created an extension method for the drop down list.
public static void SetToolTip(this DropDownList cmb)
{
if (cmb.Items.Count > 0)
{
foreach (ListItem item in cmb.Items)
{
item.Attributes.Add("Title", item.Text);
}
}
}

Just call it after calling DataBind()

Thanks,
Debata

Comments or Responses

Login to post response