views:

670

answers:

4

Hello everyone,

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.

A: 

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.

Peter
+1  A: 

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

Canavar
A: 

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?

C.McAtackney
+1  A: 

Hi there is another related stack-overflow question here:

http://stackoverflow.com/questions/182035/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).

Nils