Chris McAtackney
Chris McAtackney

Reputation: 5242

Using HTML for Listbox items

I was wondering if there was a way of using HTML for the content of my ASP:Listbox items instead of plain text? The reason I ask is because I'd like to do some extra formatting on each item in the list. Not just font changes, but perhaps icons alongside the text or table rows to divide up each list item.

I'm vaguely aware that there may be a JavaScript solution to this problem, but I'm not having much luck with it, so if anyone can offer any suggestions or pointers that'd be great.

Edit: I should clarify that my target platform is .NET 2.0 and IE6.


Peter, that's very close to what I'm after. I've done this in my .NET app;

itemToAdd.Attributes.Add("style", "padding-left: 20px; background: url(" + image + ".gif) no-repeat left center;");

This works exactly as expected in FF3, but in IE the images are not displayed for some reason. Does anyone know of any issues surrounding the use of the background CSS element in IE?

Upvotes: 1

Views: 3991

Answers (3)

Nils
Nils

Reputation: 1237

there is another related stack-overflow question here:

Is there a way to enhance by CSS an HTML <select> and its <option> on IE 6?

From that it seems like you can;t set many of the css selectors for the OPTION element inside a SELECT.

You can set some things like color and background-color in IE6 but not other things like padding (that do work in certain newer browsers).

Upvotes: 1

Canavar
Canavar

Reputation: 48088

You can't format items in a listbox. You should design your own listbox.

Maybe you can create an HTML table of items. then you can format as you want. for selection of items you can add a column with radio or checkboxes.

For ASP.NET a custom control this looks good : JavaScript ListBox Control

Upvotes: 1

Xn0vv3r
Xn0vv3r

Reputation: 18184

You can use CSS Style attributes for the listitems. But it looks like it is only possible in Firefox.


Edit: Tested it with IE 6 and it worked.

Upvotes: 0

Related Questions