ListBox鼠标悬停以显示ListItem文本

时间:2022-03-08 04:31:54

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.

我正在使用System.Web.UI.WebControls的库;从SQL表中提取数据并将它们作为listitem。但是,当用户将鼠标悬停在项目上时,它应显示文本(光标悬停的listitem文本)。我读过你需要使用System.Windows.Forms;库,但我不知道如何使用sql行填充列表框。

Someone help me how to populate a listbox from an sql table and use the mouseover event to display the listitem text?

有人帮我如何从sql表填充列表框并使用mouseover事件显示listitem文本?

I'm using C#, asp.net and visual studio (sql manangemetn 2005).

我正在使用C#,asp.net和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); 
    } 
}

1 个解决方案

#1


3  

You don't need to use any controls; just add the standard HTML attribute title to your list item, and that will display the tooltip / mouseover popup.

您不需要使用任何控件;只需将标准HTML属性标题添加到列表项中,即可显示工具提示/鼠标悬停弹出窗口。

<asp:ListBox ID="mylist" runat="server">
    <asp:ListItem Text="item1" Value="value1" title="tooltip here" />
</asp:ListBox>

To bind them to a data value, you could either extend the ListBox class, or just iterate over the items in the OnDataBound event:

要将它们绑定到数据值,您可以扩展ListBox类,或者只是迭代OnDataBound事件中的项:

foreach (ListItem item in mylist.Items) item.Attributes.Add(title, item.Value);

#1


3  

You don't need to use any controls; just add the standard HTML attribute title to your list item, and that will display the tooltip / mouseover popup.

您不需要使用任何控件;只需将标准HTML属性标题添加到列表项中,即可显示工具提示/鼠标悬停弹出窗口。

<asp:ListBox ID="mylist" runat="server">
    <asp:ListItem Text="item1" Value="value1" title="tooltip here" />
</asp:ListBox>

To bind them to a data value, you could either extend the ListBox class, or just iterate over the items in the OnDataBound event:

要将它们绑定到数据值,您可以扩展ListBox类,或者只是迭代OnDataBound事件中的项:

foreach (ListItem item in mylist.Items) item.Attributes.Add(title, item.Value);