Connection line disconnected by ASP. NET 2.0 Treeview control in IE7

Source: Internet
Author: User
Original article: http://blogs.msdn.com/carloc/archive/2007/05/23/broken-line-in-asp-net-2-0-treeview-in-ie-7.aspx

Create a very simple page in ASP. NET 2.0, add a Treeview control and setShowlines = true; Now browse the page with Internet Explorer 7: You'll very likely see something like this:

In IE 6 this looks good...

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 abve looks:

 
1: [...]
 
2: <Table cellpadding = "0" cellspacing = "0" style = "border-width: 0;">
 
3: <tr>
4: <TD>
 
5: <Div style = "width: 20px;Height: 1px">
 
6: 
 
7: </div>
 
8: </TD>
 
9: <TD>
 
10: <a id = "treeview1n1" href = "javascript: treeview_togglenode (treeview1_data, 1, treeview1n1, 'l', treeview1n1nodes)">
 
11:  
 
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! Important CSS Directive; here is how the modified source looks like:

 
1: [...]
 
2: <HTML xmlns = "http://www.w3.org/1999/xhtml">
 
3:  
 
4: <title> untitled page </title>
 
5: <style>
6:. Tree TD Div {
 
7:Height: 20px! Important
 
8:}
 
9: </style>
 
10:  
 
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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.