tags:

views:

417

answers:

4

When I add   or é to a text value of a listitem, it display the code of the HTML entity instead of the result (a space or é).

I can add "physical" non-breaking spaces or special chars, but I would like to avoid that if possible. Sometimes the data stored in database is encoded, and I don't want to always process data before displaying it.

Any solution ?

Thanks

Edit note : previous description noted it was about a dropdownlist simulating a treeview, but it was merely an example ; I can't and don't want to replace the dropdownlist by anything else.

A: 

Standard drop down lists are very poor at representing treeviews .

They can handle going one level deep if the top level is not selectable (see the optgroup element[1]), but beyond that I suggest taking a regular list (ordered or unordered) with as much nesting as you need (remember sublists go inside list items in their parent list) and including a checkbox or radio button with each selectable list item.

Some JavaScript could then be added to manipulate classes to create a drop down effect if desired.

[1] Optgroup should be able to go deeper but, IIRC, browser support is sucky.

David Dorward
+1  A: 

You can use the <optgroup> tag for hierarchical (i.e., tree-like) drop-down menus.

<select>
    <optgroup label="Parent 1">
        <option>Child 1.1</option>
        <option>Child 1.2</option>
    </optgroup>
    <optgroup label="Parent 2">
        <option>Child 2.1</option>
        <option>Child 2.2</option>
    </optgroup>
</select>
Mark Cidade
A: 

Try with ul(ol) and play with the css. You can use jquery to change style if some requirements are met (li has value attribute)

Mote
+2  A: 

ListItems are automatically HtmlEncoded.

You can HtmlDecode the list items before hand, so when they are HtmlEncoded you get the proper characters:

DropDownList1.DataSource = new List<string> { Server.HtmlDecode("A&hellip;"), Server.HtmlDecode("B&nbsp;C") };
DropDownList1.DataBind();
martin