Indent Items in a Web Forms ListBox or Adding   to ListBox

Today I needed to create a listbox that had 3 levels of indent, with dynamic data. I didn’t want 3 columns but something like this:

This is level1 with no indent

This is level2 with indent

This is level 3 with indent

Using Listbox, if you add spaces they will just smash together because of most fonts (once shown on your website, it shows correct in your datatable). If you try to add “ ”, Since unlike some Controls, in listbox you can not turn on HTMLDecode so the Listbox will just show the text “  ”.


This fix for this is to add the htmldecode with the data using Server.HTMLDecode



Row 1 with no indent

dRow(0) = dr("SQLColumn1")


Row 2 with 1 set of indents

dRow(0) = (Server.HtmlDecode("      ")) & dr("SQLColumn2")

Row 3 with 2 set of indents

dRow(0) = (Server.HtmlDecode("      ")) & (Server.HtmlDecode("      ")) & dr("SQLColumn3") 


Leave a Reply