0 Comments

If you want to show a hierarchy of data in a DropDownlist by using spaces in front of each item, then you will find that normal spaces don’t work, instead use   and Server.HtmlDecode().

 

 

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Level 1");
            DropDownList1.Items.Add("  Level 2");
            DropDownList1.Items.Add("    Level 3");
            DropDownList1.Items.Add("      Level 4");
        }
    }
}

No hierarchy!!!

 

image

 

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add(Server.HtmlDecode("Level 1".Replace(" ", " ")));
            DropDownList1.Items.Add(Server.HtmlDecode("  Level 2".Replace(" ", " ")));
            DropDownList1.Items.Add(Server.HtmlDecode("    Level 3".Replace(" ", " ")));
            DropDownList1.Items.Add(Server.HtmlDecode("      Level 4".Replace(" ", " ")));
        }
    }
}

Now with hierarchy!!!

 

image

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Related Posts