I have this small function:
// Adds to menu
public void addMenuToList(int menuVal, string menuTxt, int depth, bool hasChildren)
{
    for (int i = 0; i < depth; i++)
    {
        menuTxt = " " + menuTxt;
    }
    if (hasChildren) { menuTxt = " + " + menuTxt; }
    ListItem newItem = new ListItem();
    newItem.Text = menuTxt;
    newItem.Value = menuVal.ToString();
    parent.Items.Add(newItem);
}
Which then goes on to create the following HTML:
<select size="4" name="ctl00$mainContent$parent" id="ctl00_mainContent_parent" class="tbox widebox">
    <option selected="selected" value="0">Top Level</option>
    <option value="1"> + Boxes</option>
    <option value="2">&nbsp;&nbsp;Wrapping</option>    
    <option value="8"> + &nbsp;&nbsp;&nbsp;&nbsp;All Products</option>
</select>
It's url encoding the   to &nbsp; which spoils the formatting of the rendered select box.  Any ideas how to prevent this happening?  I need preliminary spaces in the options.
Try following:
string space = Server.HtmlDecode(" ");
for (int i = 0; i < depth; i++)
{
    menuTxt = space + menuTxt;
}
EDIT: nbsp is character with UTF-8 U+00A0 value (eg. it renders as a space, but isn't considered as a space by any of IsSpace method variants)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With