In my previous tutorials, I’d explained about country-state-city cascading for dropdownlist, dynamically bind and show data in dropdownlist, main differences between executereader executenonquery and executescalar and other more cracking tutorials on DropDownList, GridView, Asp.net here.
Now here in this tutorial, I’ll explain how you can bind asp.net dropdownlist title or tooltip to it’s list items using c# as well as vb.net with example code.
I guess you all know about how to bind data to asp.net dropdownlist, so I’m skipping that part and going to explain how you can show tooltip to asp.net dropdown list items.
Define OnDataBound Event of DropDownList – [.aspx]
To show title or tooltip, you need to add OnDataBound event of dropdownlist. Here is the sample dropdownlist with OnDataBound event:
After adding OnDataBound event to dropdown, choose your language (that is .cs or .vb) and add the following code to your code-behind file.
Bind Asp.net DropDownList Title or Tooltip Using OnDataBound Event – [C#]
DropDownList dd = sender as DropDownList;
if (dd != null)
foreach (ListItem li in dd.Items)
li.Attributes[“title”] = li.Text;
Bind Asp.net DropDownList Title or Tooltip Using OnDataBound Event – [Vb]
Dim dd As DropDownList = TryCast(sender, DropDownList)
If dd IsNot Nothing Then
For Each li As ListItem In dd.Items
li.Attributes(“title”) = li.Text