VS 2005 ASP.NET 2.0 DropDownList ToolTip in IE7

You can set the title attribute on the drop down list items to have ToolTip popups on your DropDownList items. This does not work in IE6 but works in IE7. For example you can do it right in the aspx like this:

<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem title="Choice 1 ToolTip" Value="1">Choice 1asp:ListItem>
            <asp:ListItem title="Choice 2 ToolTip" Value="2">Choice 2asp:ListItem>
asp:DropDownList>

Visual Studio will say that “Attribute 'title' is not a valid attribute of element 'ListItem'.” but it will run fine.
Or you can do it in the code behind like this:

Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.DataBound
Dim toolTip As String = string.Empty
For Each item As ListItem In DropDownList1.Items
toolTip = GetToolTips.(Integer.Parse(item.Value))
item.Attributes.Add("title", toolTip)
Next
End Sub

Where GetToolTips is a custom function to retrieve tooltip text based on the passed in value.

Comments

Popular posts from this blog

Show/Hide formatting text in MS Word 2010

Microsoft.ApplicationBlocks. ExceptionManagement The event source x does not exist error

ASP.NET 2.0 DropDownList EnableViewState