Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

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!

Technorati Tags: ,,
Posted on Thursday, May 7, 2009 6:01 PM ASP.NET , C# , Tips&Tricks | Back to top


Comments on this post: Add Spacing/Indention in DropDownList Items

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net