Adding nbsp to asp:DropDownList title

I was trying to mimmick a tree-list in a drop down box. As wee all know, simpler is better, so I just added a few  ‘s in front of my title before adding the ListItem to the DropDownList:

ListItem listItem = new ListItem("  " + Item.Title, item.ID.ToString());

But because the ListItem is clever enough to encode the contents of the title field, all I get is:

Added   in drop down failed

Added in drop down failed

How can I overcome this? Simply by using Server.HtmlDecode(). Here is a small function that returns a string of HtmlDecoded  ‘s that can be used in the dropdown:

private string Prefix(int count)
  if (count == 0)
    return “”;
  StringBuilder sb = new StringBuilder();
  for (int i=0;iDrop down with tree-like structure[/caption]


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in .net, c#, General .NET and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.