列表框asp.net中列表项的点

时间:2013-08-17 11:40:02

标签: asp.net css listboxitem

我在asp.net页面中使用ASP ListBox。我显然在这个控件中添加了项目。我已经定制了listitems的个别背景颜色。当用户将鼠标悬停在它上面时,我也想将Cursor更改为指针。我正在努力实现这一目标。有没有快速的方法来做到这一点?我不想使用它的HTML控件版本。它必须使用ASP.NET列表控件。

提前致谢...

1 个答案:

答案 0 :(得分:1)

快速执行此操作的方法是通过CSS,如下所示:

通过引用单个元素ID:

#YourListBoxID:hover { 
    cursor: pointer; 
}

通过制作CSS类:

.HoverCursorPointer:hover {
     cursor: pointer;
}

然后您需要将CSS类应用于ASP.NET ListBox,如下所示:

<asp:ListBox id="ListBox1" runat="server" CssClass="HoverCursorPointer">

</asp:ListBox>

仅供参考,以下是CSS cursor property values的列表。

更新:

要将悬停光标也应用于每个列表项,请执行以下操作:

protected void ListBox1_DataBound(object sender, EventArgs e)
{ 
    ListBox lb = sender as ListBox;
    foreach (ListItem item in lb.Items)
    {
        item.Attributes["class"] = "HoverCursorPointer"
    }
}