12 December, 2011
0 Comments
1 category
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!!!
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!!!
Category: Uncategorized