May 25, 2010

Remove the Whitespace generated for each Parent TreeNode in an ASP.NET TreeView




I was working on a TreeView bound to a SiteMap control. Due to a space constraint while displaying the TreeView, I had to save as much space as I could while displaying my TreeView. Now by default, when a TreeView is generated, the Parent Root Nodes have a whitespace indent as visible below

image

When the TreeView gets rendered, ASP.NET generates a number of HTML Table tags to format it’s layout. So to remove the whitespace before each parent node, just use the following CSS

<style type="text/css">
.tv table tbody tr td:first-child
{
display:none;
}
</style>

where tv is the CssClass applied to the TreeView.

<asp:TreeView ID="TreeView1" runat="server"
DataSourceID="SiteMapDataSource1" CssClass="tv">

The resultant output is as shown below with the extra whitespace removed:

image



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Remove the Whitespace generated for each Parent TreeNode in an ASP.NET TreeView"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions