Vinz' Blog

"Code, Beer and Music" ~ my way of being a programmer!
posts - 124, comments - 367, trackbacks - 0

My Links

News

Archives

Image Galleries

Add Spacing/Indention in DropDownList Items

The following code block below will allow you to display spacing or indention in the DropDownList items..

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            const string spaceChar = "    ";

            DropDownList1.Items.Add(new ListItem("Parent Item 1", "Parent Item 1"));

            DropDownList1.Items.Add(new ListItem("Parent Item 2", "Parent Item 2"));

            DropDownList1.Items.Add(new ListItem(Server.HtmlDecode(spaceChar + "Sub1 Item 2"), "Sub1 Item 2"));

            DropDownList1.Items.Add(new ListItem(Server.HtmlDecode(spaceChar + "Sub2 Item 2"), "Sub2 Item 2"));

            DropDownList1.Items.Add(new ListItem(Server.HtmlDecode(spaceChar + spaceChar + "Sub1 Item 3"), "Sub1 Item 3"));

            DropDownList1.Items.Add(new ListItem("Parent Item 3", "Parent Item 3"));

        }

    }


As you can see we just Decode the character    the HTML equivalent for Space and then append it to the actual ListItems of the DropDownList..

See the sample output below:




That's it! Hope you will find this example useful!

Print | posted on Thursday, May 07, 2009 6:01 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: