0

After a long time searching for this problem I've decided to try my luck here... I'm trying to add a tooltip (title) for the items in a Drop Down List.The title is showed in IE and Firefox browsers. The DDL is creating dynamically and the DDL's DataSource is a list called "labCourses" .This is my code:

 protected void Page_Load(object sender, EventArgs e)
{
    ExpScheduleClass ExpSC = new ExpScheduleClass();
    List<string> labCourses = ExpSC.getCourseList();
    // dynamically create a dropdown list (aka DDL)
    DDLCourses = new DropDownList();
    DDLCourses.DataSource = labCourses; // set the data source
    DDLCourses.DataBind(); // bind the data to the DDL control
    BindTooltip(DDLCourses);
    DDLCourses.AutoPostBack = true;
    DDLCourses.SelectedIndexChanged += DDLCourses_SelectedIndexChanged;
    coursePH.Controls.Add(DDLCourses);
}
public void BindTooltip(ListControl lc)
{
    for (int i = 0; i < lc.Items.Count; i++)
    {
        lc.Items[i].Attributes.Add("title", lc.Items[i].Text);
    }
}

I looked at the option element with the web inspector and the title was there (in the html), but is does not shown when the mouse was over the option. In other browsers the title is shown on mouse hover. What may be the cause for this? Thank you very much...

  • what is the rendered HTML? – T McKeown Jun 02 '15 at 00:03
  • I dont' understand this clearly. DropDownList will render a – Tran Nguyen Jun 02 '15 at 00:10
  • It was: `` – Shahar Ehrenhalt Jun 02 '15 at 00:14
  • @WeryNguyen maybe you're right, I search for it a lot and saw question and explaining on how to do it, like this [link](http://stackoverflow.com/questions/15872488/tooltip-for-drop-down-list-items), and this [link](http://stackoverflow.com/questions/3249591/how-can-i-display-a-tooltip-on-an-html-option-tag), and this [link](http://www.webblogsforyou.com/how-to-show-title-or-tooltip-in-asp-net-dropdownlist-using-c-vb/). Maybe it worked with old browsers. I'm using chrome. Do you know a way to display a title for an item? TNX a lot. – Shahar Ehrenhalt Jun 02 '15 at 00:37
  • Oh, you may be right about adding the title to option tag. I just found out that in Chrome, the tooltips don't show up but in FF and IE, they are displayed. Weird isn't it? So the question come down to which browser do you want to support. If you are still keen on this, i think there is only dirty option of using javascript, css to display to popup in a list instead which would be too much for this little thing IMO. But have a look here: http://stackoverflow.com/a/3314790/856540 – Tran Nguyen Jun 02 '15 at 00:52
  • You're right it does work on IE. Very annoying. I guess you're right and i'll drop this issue. I needed it to make my options much smaller but I guess I'll stay with the long strings. TNX. – Shahar Ehrenhalt Jun 02 '15 at 01:01

0 Answers0