AspnetO

We code, that works!

  • Home
  • Asp.net
  • MVC
  • Interview Questions
You are here: Home / Asp.net / Bind Asp.net DropDownList Title or Tooltip From Code-behind

Bind Asp.net DropDownList Title or Tooltip From Code-behind

By: Mayank Modi | Falls In: Asp.net, C#, VB | Last Updated: Oct 05, 2020

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:

<asp:DropDownList ID=”ddlSubjects” runat=”server” OnDataBound=”ddlSubjects_OnDataBound”>
</asp:DropDownList>
Note: If you want to check how to get data from database and bind data to asp.net dropdownlist from code-behind dynamically, visit here.

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#]

protected void ddlSubjects_OnDataBound(object sender, EventArgs e)
{
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]

Protected Sub ddlSubjects_OnDataBound(ByVal sender As Object, ByVal e As EventArgs)
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
Next li
End If
End Sub

Example Result

How to Show Title or Tooltip in Asp.net DropDownList using C# or Vb.net?
You may also like, 100+ Frequently Asked Interview Questions on Asp.net, Top 10 OOPS Concepts in .NET C# with Examples here.

Download Example

Icon

Bind Asp.net DropDownList Examples

1 file(s) 46.14 KB
Download This Example

Git Repo

git clone https://github.com/immayankmodi/bind-dropdown-list-asp-net-c-vb.git

Signup Today And Get Latest Tutorials For Free!

Subscribe to us and get free latest tutorials notifications whenever we publish a new contents.

<

About Mayank Modi

Mayank is a web developer and designer who specializes in back-end as well as front-end development. He's a Founder & Chief Editor of AspnetO. If you'd like to connect with him, follow him on Twitter as @immayankmodi.

Comments

  1. kekiz says

    Sep 22, 2014 at 9:53 PM

    Your post is not working that items of dropdownlist are creating manually in asp.x page. So what do i?
    (How to show title or tooltip in asp .net dropdownlist using c# or vb)

    Reply
    • Kekiz says

      Sep 22, 2014 at 10:20 PM

      I solved my problem.I used Title property of ListItem

      Reply
      • Mayank Modi says

        Sep 23, 2014 at 12:34 AM

        Hi kekiz, This post is specific to add “title” attribute from code-behind file using c# or vb. You can also use “Title” attribute or property from .aspx page (I guess you did it!) when your data are static.

        Thanks for visiting and posting your valuable comments. 🙂

Leave a Reply Cancel reply

Search Your Topic



Social Connections

  • 1,438 Fans
  • 3,098 Followers
  • 51 Followers
  • 1,559 Subscribers

Get Latest Tutorials For Free



Top Posts

  • CSS3 Transition: fadeIn and fadeOut like Effects to Hide Show Elements
  • Asp.net TextBox: How to Get Set TextBox Value or Text in JavaScript
  • Show Confirm Message Box from Code-behind in Asp.net
  • Show Alert Message Box from Code-behind in Asp.net C# Vb
  • Asp.net TextBox: How to Get Set TextBox Value or Text in jQuery

Contribute to AspnetO

If you want to contribute your unique blog articles or tutorials (Free / Paid) to AspnetO in any languages, you're most welcome. Just send me your previous articles, and topics on which you are interested to post an tutorial. Contact us at email listed in contact us page. Selected candidates will be contacted.

Search by Tags

Ado.net Ajax appSettings Asp.net C# CheckBox CheckBoxList ConnectionStrings Control CSS CSS3 Difference Download DropDownList Export Facebook fadeIn fadeOut fadeTo fadeToggle File File Extension FileUpload Function GridView IIS Interview Questions JavaScript jQuery MVC OOP RadioButtonList RDP Repeater Send Mail Solutions Split SQL Stored Procedure TextBox Upload Validation VB Web.config Web Hosting

The Man Behind AspnetO

Mayank Modi

Hi there,

Myself Mayank Modi, a Full Stack Developer (.NET Stack) and a blogger from Surat, India.

I'm welcoming you to my blog - AspnetO, a programmers community blog where we code, that works!

I started AspnetO as a hobby and now we're growing day by day. We're now having 5000+ programmers that get benefits and learn new things about website design and development under our community blog.

Here at AspnetO, I write about Beginners to Advance level of tutorials on programming languages like Asp.net using C# and Vb.net, MVC, SQL Server, JavaScript, jQuery etc. In sort, all about .NET Framework and website development stuff and sometimes sharing tips and tricks that can help you to grow up your programming skills.

You can get more details about me and my blog at About us page.

Subscribe To Newsletter

Enter your email address to subscribe to this blog and receive notifications of new posts right to your inbox

Join 1000+ other subscribers

<

Recent Posts

  • Main Difference between SessionState and ViewState in Asp.net
  • How to Get appSettings Value from Web.config File?
  • How to Get ConnectionString from Web.config in Asp.net?
  • Difference between appSettings and connectionStrings in Web.config
  • Get Folder Files List and Export to CSV in .NET
  • Get Files List From Directory Recursively in C# Vb.net
  • Get Hash Value From Current Page URL In jQuery
  • Handle Multiple Submit Buttons in Single MVC Form

Copyright © 2014 - 2021 · All Rights Reserved.

About | Copyrights | Privacy | Terms | Contact | Advertise | Sitemap
Previous Call Server-side Function Using jQuery Ajax Call
Next Bind Asp.net DropDownList Dynamically In C# Vb.net