johnc
johnc

Reputation: 40233

Show tooltip when selecting item on asp:DropDownList

I have an asp:DropDownList on a page that, due to the 1024x768 development standard can truncate some of the text values in the dropdown (not enough of them, apparently, to redesign the layout ), so I need to display a tooltip of the selected value when a dropdown item is being selected (i.e. when the dropdown is shown and an item is being hovered over), preferably only when the text for that item is being truncated.

Is this possible by default, javascript hacking or only my imagination?

Upvotes: 1

Views: 13069

Answers (3)

Peter Bromberg
Peter Bromberg

Reputation: 1496

foreach (ListItem _listItem in this.DropDownList1.Items)    
{     
  _listItem.Attributes.Add("title", _listItem.Text); 

}

// add a tooltip for the selected item also

DropDownList1.Attributes.Add("onmouseover", this.title=this.options[this.selectedIndex].title");

Upvotes: 3

jay
jay

Reputation:

You could also do a postback and load data into a help icon. boxover works pretty well.

Upvotes: 0

BenAlabaster
BenAlabaster

Reputation: 39874

Add the "Title" attribute to your list items with your tooltip info in there. It's not an existing item in the intellisense, but it should work. It does on my system. Now, I'm not exactly sure how to do this if you're DataBinding your drop down list to a data source. But if you're hard coding in the ASPX or in the codebehind, that's how you can do it.

<asp:DropDownList id="ddl1" runat="server">
  <asp:ListItem Text="Display text" Value="1" Title="This is my tooltip"></asp:ListItem>
</asp:DropDownList>

Upvotes: 0

Related Questions