views:

33

answers:

2

Hi I have a DropDownList bounded from the code behind. How can I use the DataTextField as a ToolTip of the DropDownList?

DropDownList list = this.DropDownList1;
list.DataSource = GetData();
list.DataTextField = "DisplayString";
list.DataValueField = "DataValue";
list.DataBind();

I want the bounded Field DisplayString to bounded also in the ToolTip. Is this possible without using the DataBound event of the DropDownList?

A: 

Well with some javascript work,it's quite possible.

First you create a div inside your html side with mouse out event

<div id="tooltip" style="display:none;" onmouseout="hidetooltip();"></div>

then some javascript work is required to insure your when you hover you dropdownlist item it shows a tooltip

function showtooltip(element) {
   //select focused elements content to show in tooltip content
   document.getElementById("tooltip").innerHTML = 
          element.options[element.selectedIndex].text;
   //show tooltip
   document.getElementById("tooltip").style.display = "block";
}

function hidetooltip() {
   //hide tooltip
   document.getElementById("tooltip").style.display = "none";
}

The last part is adding mouse over and out event to your dropdownlist

<asp:DropDownList ... onmouseover="showtooltip(this)" 
                      onmouseout="hidetooltip()" ... >

Then it should work.You may need to add extra style for your tooltip.
Hope this helps
Myra

Myra
close, but I want the tooltip for each list item, not only on the selected item.
rob waminal
same thing can be implemented on hover effect as well
Myra