Question

I am using an ASP ListBox in my asp.net page. I obviously add items to this control. I have customised individual background colours of the listitems. I also want to change the Cursor to a pointer when the User hovers over it. I am struggling to achieve this. Is there a QUICK way to do this at all? I do not want to use the HTML control version of this. It has to be using the ASP.NET list control.

Thanks in advance...

Was it helpful?

Solution

The quick way of doing this is through CSS, like this:

By referencing the single element ID:

#YourListBoxID:hover { 
    cursor: pointer; 
}

By making a CSS class:

.HoverCursorPointer:hover {
     cursor: pointer;
}

Then you would need to apply the CSS class to your ASP.NET ListBox, like this:

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

</asp:ListBox>

Just for reference, here is a list of CSS cursor property values.

UPDATE:

To apply the hover cursor to each list item as well, then do this:

protected void ListBox1_DataBound(object sender, EventArgs e)
{ 
    ListBox lb = sender as ListBox;
    foreach (ListItem item in lb.Items)
    {
        item.Attributes["class"] = "HoverCursorPointer"
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top