使用转发器逐列创建表

时间:2016-03-03 18:38:31

标签: c# asp.net

我正在尝试为网站制作一个比较表。有一个转发器,它有一个对象列表作为数据源。

表格必须如此:

Product1        Product2        Product3
ProductName1    ProductName2    ProductName3
ProductImage1   ProductImage2   ProductImage3

问题是我在转发器中有<tr><td>标签,这导致ProductNames不在同一行,所以我明白了:

Product1       
ProductName1    
ProductImage1   

Product2       
ProductName2    
ProductImage2   

Product3       
ProductName3    
ProductImage3

有没有办法逐列填写表格,不同的项目在同一行?

编辑(添加代码):

<asp:PlaceHolder runat="server" ID="phPopUp">
    <div id="popup-wrapper">
        <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
            <HeaderTemplate>
                <table class="table-wrapper">
            </HeaderTemplate>
            <ItemTemplate>
                    <tr>
                        <td>
                            <%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
                        </td>
                    </tr>
                    <tr>
                        <td class="product-image">
                            <img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
                                alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
                                title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%-- Features --%>
                            <asp:Literal runat="server" ID="ltFeatures" />
                        </td>
                    </tr>
                    <%--                    <tr>
                        <td>
                            <asp:Literal ID="ltApplication" runat="server" />
                        </td>
                    </tr>--%>
                    <tr>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Literal ID="colors" runat="server" />
                            <asp:BulletedList runat="server" ID="blColors" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Literal runat="server" ID="ltVolumes" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%-- substrate --%>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%-- finish --%>
                        </td>
                    </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

1 个答案:

答案 0 :(得分:1)

在每一行重复转发器:

<asp:PlaceHolder runat="server" ID="phPopUp">
    <div id="popup-wrapper">
        <table class="table-wrapper">
            <tr>
                <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                    <ItemTemplate>
                        <td>
                            <%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
                        </td>

                    </ItemTemplate>
                </asp:Repeater>
            </tr>
            <tr>
                <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                    <ItemTemplate>
                        <td class="product-image">
                            <img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
                                 alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
                                 title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
                        </td>

                    </ItemTemplate>
                </asp:Repeater>
            </tr>
            <tr>
                <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                    <ItemTemplate>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
                        </td>

                    </ItemTemplate>
                </asp:Repeater>
            </tr>
            <tr>
                <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                    <ItemTemplate>
                        <td>
                            <%-- Features --%>
                            <asp:Literal runat="server" ID="ltFeatures" />
                        </td>

                    </ItemTemplate>
                </asp:Repeater>
            </tr>
            <%--                    <tr>
            <td>
                <asp:Literal ID="ltApplication" runat="server" />
            </td>
        </tr>--%>
            <tr>
                <asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                    <ItemTemplate>
                        <td>
                            <%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
                        </td>

                    </ItemTemplate>
                </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <asp:Literal ID="colors" runat="server" />
                        <asp:BulletedList runat="server" ID="blColors" />
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <asp:Literal runat="server" ID="ltVolumes" />
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <%-- substrate --%>
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
            <tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
                <ItemTemplate>
                    <td>
                        <%-- finish --%>
                    </td>

                </ItemTemplate>
            </asp:Repeater>
            </tr>
        </table>