troubleshooting Question

How to set the dropdownlist title attibute to a value from a database

Avatar of WNottsC
WNottsCFlag for Afghanistan asked on
.NET ProgrammingASP.NET
40 Comments1 Solution643 ViewsLast Modified:
I currently have an asp.net webform language vb.net

I have a dropdownlist that is databound to a SQL Server Stored Procedure

I have managed to get a tooltip per data item as shown below.  However this shows the "Title" attibute which is just the same as the 'DataTextField' which is a SoftwareCategory Column   what I want this to be is an additional Column called SoftwareCategoryDescription.

I hope this makes sense



<asp:DropDownList ID="SoftwareTypeDropDownList0" runat="server"
                                                                AppendDataBoundItems="True" CssClass="IncidentDropDownList"
                                                                DataSourceID="SqlSoftwareCategory" DataTextField="SoftwareCategory"
                                                                DataValueField="SoftwareCategoryID"
                                                                SelectedValue='<%# Bind("SoftwareCategoryID") %>'
                                                                ondatabound="SoftwareTypeDropDownList0_DataBound">
                                                                <asp:ListItem Text="" Value=""></asp:ListItem>
                                                            </asp:DropDownList>


Protected Sub SoftwareTypeDropDownList0_DataBound(sender As Object, e As EventArgs)
        Dim ddl As DropDownList = TryCast(sender, DropDownList)

        If ddl IsNot Nothing Then

            For Each _listItem As ListItem In ddl.Items

'Either one of these two work I have just commented out one to show what I have tried
                '                _listItem.Attributes.Add("onmouseover", "this.title=this.options[this.selectedIndex]")
                _listItem.Attributes.Add("title", _listItem.Text)
 
           Next


        End If
    End Sub
ASKER CERTIFIED SOLUTION
Rouchie

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 40 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 40 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros