简体   繁体   English

怎么能 <td> 和 <tr> ItemTemplate内的标签不能嵌套在表格内?

[英]How can <td> and <tr> tags inside an ItemTemplate not be nested inside a table?

I read here that a td tag must be nested, so I'm confused when I see the ItemTemplate property tag of a ListView looking like this: 在这里读到td标签必须嵌套,所以当我看到ListView的ItemTemplate属性标签看起来像这样时我很困惑:

<ItemTemplate>    
                            <td id="Td2" runat="server">      
                                <table>        
                                    <tr>          
                                        <td>&nbsp;</td>          
                                        <td>
                                            <a href="ProductDetails.aspx?productID=<%#:Item.ProductID%>">
                                                <img src="/Catalog/Images/Thumbs/<%#:Item.ImagePath%>" 
                                                    width="100" height="75" /></a> 
                                        </td>
                                        <td>
                                            <a href="ProductDetails.aspx?productID=<%#:Item.ProductID%>">
                                                <span class="ProductName">
                                                    <%#:Item.ProductName%>
                                                </span>
                                            </a>            
                                            <br />
                                            <span class="ProductPrice">           
                                                <b>Price: </b><%#:String.Format("{0:c}", Item.UnitPrice)%>
                                            </span>
                                            <br />            
                                        </td>        
                                    </tr>      
                                </table>    
                            </td>  
                        </ItemTemplate>  

Does this have to do with the fact that ListView inherits from some class and implements a ton of interfaces? 这是否与ListView从某个类继承并实现大量接口的事实有关? Or does it have to do with some aspect of ItemTemplate that I'm not familiar with? 或者它与我不熟悉的ItemTemplate的某些方面有关系吗? Is my source wrong or is it "just an ASP thing"? 我的来源是错的还是“只是一个ASP的东西”?

It's just the way asp.net has you define your controls. 这就是asp.net定义控件的方式。 Once the asp.net page is rendered (converted to pure html), those td elements should be nested in a tr . 一旦渲染了asp.net页面(转换为纯html),那些td元素应该嵌套在tr You can see the output by viewing the source of the page in your browser. 您可以通过在浏览器中查看页面源来查看输出。

I don't know what your LayoutTemplate looks like but this really has nothing to do with the ListView per se but more with the HTML layout that the developer chose. 我不知道您的LayoutTemplate是什么样的,但这实际上与ListView本身无关,而是与开发人员选择的HTML布局有关。 td's best belong inside a tr but these are just tags. td最好属于tr,但这些只是标签。 You can change the css and redefine however you want. 您可以根据需要更改css并重新定义。 The browser will then interpret it and display it and then you get to deal with the aftermath of your choices =). 然后,浏览器将对其进行解释并显示它,然后您将处理您的选择的后果=)。

A possible way the code above makes sense is: 上面的代码有意义的可能方式是:

<LayoutTemplate>
    <table border="0" cellpadding="1">
        <tr>
            <th>Product</th>
        </tr>
        <tr>
            <td id="itemPlaceholder" runat="server"></td>
        </tr>
    </table>
</LayoutTemplate>

This would make a single column outer table with a product heading and then each row of that table would contain your inner table (per product) above. 这将使单个列外表具有产品标题,然后该表的每一行将包含上面的内部表(每个产品)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM