• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...
Common Tasks
  • Blog Home
  • Email Blog Author
  • RSS for comments
  • RSS for posts
Search
Tags
  • .NET Framework
  • Ajax/Javascript
  • ARR
  • ASP.NET
  • CLR
  • Cool stuff
  • DataAccess
  • Debugging/Windbg
  • Hotfix/Service Pack
  • IDEVDataCollector
  • IIS
  • Internet Explorer
  • Italian techs
  • LogParser
  • OT
  • Personal
  • Productivity
  • Random
  • Scripting/ASP
  • Security
  • Technology
  • Tools
  • Troubleshooting
  • Vista/Longhorn
  • Visual Studio
Archives
Archives
  • January 2013 (2)
  • November 2010 (1)
  • October 2010 (1)
  • July 2010 (2)
  • April 2010 (1)
  • March 2010 (2)
  • February 2010 (2)
  • January 2010 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (1)
  • July 2009 (5)
  • June 2009 (1)
  • May 2009 (1)
  • April 2009 (3)
  • March 2009 (3)
  • February 2009 (5)
  • January 2009 (3)
  • December 2008 (5)
  • November 2008 (3)
  • October 2008 (2)
  • September 2008 (3)
  • August 2008 (3)
  • July 2008 (3)
  • June 2008 (5)
  • May 2008 (4)
  • April 2008 (8)
  • March 2008 (4)
  • February 2008 (5)
  • January 2008 (2)
  • December 2007 (4)
  • November 2007 (6)
  • October 2007 (6)
  • September 2007 (8)
  • August 2007 (6)
  • July 2007 (7)
  • June 2007 (10)
  • May 2007 (9)
  • April 2007 (12)
  • March 2007 (8)
  • February 2007 (5)
  • January 2007 (3)
  • December 2006 (1)
  • November 2006 (4)
  • October 2006 (2)
  • September 2006 (9)
  • August 2006 (2)
  • July 2006 (1)

Broken line in ASP.NET 2.0 TreeView in IE 7

MSDN Blogs > Never doubt thy debugger > Broken line in ASP.NET 2.0 TreeView in IE 7

Broken line in ASP.NET 2.0 TreeView in IE 7

Rate This
Carlo Cardella
22 May 2007 11:48 PM
  • Comments 53

Create a very simple page in ASP.NET 2.0, add a TreeView control and set ShowLines=true; now browse the page with Internet Explorer 7: you'll very likely see something like this:

treeview broken lines

 

In IE 6 this looks good... smile_thinking

The point is that Internet Explorer 7 changes the boxing model: now a box that's too small to accomodate ita content won't stretch like it does on all other browsers including IE6, it will try to stay as small as possible. The problem in this case is that the DIV tags generated by the control are just 1 pixel height, which was working fine until now. Here is how the "View source" for the page above looks:

   1: [...]
   2: <table cellpadding="0" cellspacing="0" style="border-width:0;">
   3:     <tr>
   4:         <td>
   5:             <div style="width:20px;height:1px">
   6:                 <img src="/TreeViewSample/WebResource.axd?d=vGK_uMmdWLf5UZMMUhv9tSAl-YQg-jrsZ90xzYAI6TE1&amp;t=632985107273882115" alt="" />
   7:             </div>
   8:         </td>
   9:         <td>
  10:             <a id="TreeView1n1" href="javascript:TreeView_ToggleNode(TreeView1_Data,1,TreeView1n1,'l',TreeView1n1Nodes)">
  11:                 <img src="/TreeViewSample/WebResource.axd?d=vGK_uMmdWLf5UZMMUhv9tfjlKbdZ_ojL4O8CY0ydKO_HFK9lO1t2cZ2AjaDIqJy_0&amp;t=632985107273882115" 
  12:                 alt="Collapse New Node" style="border-width:0;" />
  13:             </a>
  14:         </td>
  15:         <td style="white-space:nowrap;">
  16:             <a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','sNew Node\\New Node')" 
  17:                 onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t1');" id="TreeView1t1">New Node</a>
  18:         </td>
  19:     </tr>
  20: [...]

As you can see, the first DIV tag contains a style definition with "height:1px"; that's the problem.

And now, here is how we can sort this out:

  • Create a new style definition in your page (or create an external .css file and link it in your pages, pedending on your needs)
  • Add the following class definition: ".tree td div {height: 20px !important}" (of course without quotation marks)
  • In your TreeView component add a referende to CssClass="tree"

Note that normally the style defined in the DIV takes precedence over the style defined at page level (or external .css file), but since in this case we need to override that setting, we can use the !important CSS directive; here is how the modified source looks like:

   1: [...]
   2: <html xmlns="http://www.w3.org/1999/xhtml">
   3: <head runat="server">
   4:     <title>Untitled Page</title>
   5:     <style>
   6:         .tree td div {
   7:             height: 20px !important
   8:         }
   9:     </style>
  10: </head>
  11: <body>
  12:     <form id="form1" runat="server">
  13:         <div>
  14:             <asp:TreeView ID="TreeView1" runat="server" ShowLines="True" CssClass="tree">
  15:                 <Nodes>
  16:                     <asp:TreeNode Text="New Node" Value="New Node">
  17:                         <asp:TreeNode Text="New Node" Value="New Node">
  18:                             <asp:TreeNode Text="New Node" Value="New Node">
  19: [...]

And the resulting page:

treeview fixed page

 

P.s.: thanks to my colleague Markus Rheker for this one! smile_regular

 

Carlo

  • 53 Comments
ASP.NET, Internet Explorer
Leave a Comment
  • Please add 4 and 5 and type the answer here:
  • Post
Comments
  • anothr user
    24 May 2007 10:35 AM

    One new subscriber from Anothr Alerts

  • Blog Comunitario
    12 Jun 2007 12:46 PM

    Para poder ver las líneas que unen los nodos en un TreeView, hice uso de las siguientes propiedades LineImagesFolder

  • Matthew Weaver
    8 Jul 2007 1:20 AM

    The listed changes had no affect.  I still get broken vertical lines with IE7 and FF.

  • Carlo Cardella
    8 Jul 2007 3:20 PM

    Uhm... weird, I tested them before posting... Matthew, are you sure you are using the right values? If you copy the code above and test in a sample page, what do you get?

  • Robotacon
    31 Jul 2007 10:11 AM

    Matthew Weaver prolly forgot this step:

    In your TreeView component add a referende to CssClass="tree"

  • Boogie
    8 Aug 2007 8:08 AM

    Excellent info 2nd link on goog

    Thanks!!!

  • Karl
    24 Aug 2007 6:51 PM

    Awesome. Worked like a charm. I was getting sick of looking at those broken lines :)

  • Asu
    21 Sep 2007 2:26 PM

    Excellent job :) the only reason i wasn't using the css adapted treeview was for the lines.

  • david smith
    28 Sep 2007 12:47 PM

    Superb!  I've been trying to sort out these gaps for months...  

  • xh
    28 Sep 2007 11:00 PM

    thanks for the tip!

  • Jaacob
    2 Oct 2007 6:38 AM

    thanks a lot! I wouldn't find out..

  • Pavel
    17 Oct 2007 2:24 AM

    Greate respect for solve this

  • Ralph de Ruijter
    19 Oct 2007 5:37 AM

    Great post, I have been looking into this myself and also figured out the 1px height problem but couldn't solve it.

    Thx for your post!

  • Eddy
    31 Oct 2007 12:03 PM

    The solution works great.

    Unfortunately, lines break again when you set treeview's NodeWrap property to true, and a treeview item spans across multiple lines.

  • Carlo Cardella
    3 Nov 2007 8:48 PM

    True... I guess that's because those dotted lines are actually images (if you use IE developer toolbar you can quickly highlight them all) and are not easilly customizable, unless maybe you use your own set of images for the control. I tried to tweak it with some stylesheet properties but with no luck so far... :-(

    Let's see if I can come up with something useful

Page 1 of 4 (53 items) 1234
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415