I have a dropdownlist and I want to add tooltip for dropdownlist items. I tried with following code, but it does not work;
for(int d=0;d<drpID.Items.Count;d++)
{
drpID.Items[d].Attributes.Add("title", drpID.Items[d].Value);
}
Can anyone help me on this?
Try like this;
You should use
.Text
property for tooltip, not for.Value
.Check out for this link: http://www.dotnetspider.com/resources/5099-Tool-tip-for-DropDownList-ASP-NET.aspx
I know this thread was regarding a databound control, but in the infrequent case where you have actually hard coded the ListItem values in the aspx page, I simply added a
attribute to the ListItem tag itself and it worked just fine. Sure, I got a complaint about that not being a valid attribute but when the page rendered, it came along and then it WAS a valid attribute.
Try following code:
You should try this
I've just had to implement a tooltip on a programatically populated DropDownList. I found that the title attribute was being set to the Text property automatically and I couldn't override it, even at PreRender.
None of the suggestions on this thread worked, and I was eventually forced to use a jQuery approach.
When creating the list item I set a custom attribute with the tooltip text
Then fire the method below with a start up script
Pretty it ain't. But it works.