I am using the library using System.Web.UI.WebControls; to extract data from a SQL table and put them as the listitem. However, when the user hovers over the item, it should display the text (the text of the listitem the cursor is hovering). I read that you need to use the System.Windows.Forms; library but I don’t know how that will work with populating the listbox with sql rows.
Someone help me how to populate a listbox from an sql table and use the mouseover event to display the listitem text?
I’m using C#, asp.net and visual studio (sql manangemetn 2005).
Edit ondatabound
protected void test123(object sender, EventArgs e)
{
foreach (ListItem item in lstService.Items)
{
item.Attributes.Add("title", item.Value);
}
}
You don’t need to use any controls; just add the standard HTML attribute
titleto your list item, and that will display the tooltip / mouseover popup.To bind them to a data value, you could either extend the
ListBoxclass, or just iterate over the items in theOnDataBoundevent: