使用 ASP 中继器创建 HTML 表格,水平重复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9361729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:39:29  来源:igfitidea点击:

Create a HTML table with an ASP repeater, repeating horizontally

htmlasp.nethtml-tablerepeater

提问by Filburt

I'm trying to build a HTML table using an ASP repeater:

我正在尝试使用 ASP 中继器构建 HTML 表:

<asp:Repeater ID="RepeaterVersionsForPie" runat="server">
    <ItemTemplate>
        <table id="VersionsTable" >

                <tr>
                    <th>
                    <%#Eval("nameVersion")%>
                    </th>

                </tr>

    </ItemTemplate>
    <ItemTemplate>
        <tbody>
            <tr>
                <td tag="<%#Eval("idVersion")%>">
                    <%#Eval("NumberOfCompaniesUsingThisVersion")%>
                </td>
            </tr>
        </tbody>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

This is a basic table which consists in two lines and X columns. The second line appears without any problems while the first one is invisible. Can anyone help to find what's missing? Thanks in advance.

这是一个由两行和 X 列组成的基本表。第二行出现没有任何问题,而第一行不可见。任何人都可以帮助找到丢失的东西吗?提前致谢。

回答by Filburt

I think the core problem is that Repeaterisn't designed to repeat horizontally.

我认为核心问题是它Repeater不是为了水平重复而设计的。

Maybe you should try using DataListwhich allows to specify the RepeatingDirection.

也许您应该尝试使用允许指定重复方向的DataList

Update

更新

If you don't need to repeat horizontally (like your question suggests "...two lines and X columns") your Repeatershould look like this

如果您不需要水平重复(就像您的问题建议“...两行和 X 列”),您Repeater应该看起来像这样

<asp:Repeater ID="RepeaterVersionsForPie" runat="server">

    <HeaderTemplate>
        <table id="VersionsTable">
    </HeaderTemplate>

    <ItemTemplate>
        <tr>
            <th><%# Eval("nameVersion") %></th>
            <!-- Important: Put attributes in single quotes so they don't get
                 mixed up with your #Eval("xxx") double quotes! -->
            <td tag='<%#Eval("idVersion")%>'>
                <%# Eval("DocumentName") %>
            </td>
        </tr>
    </ItemTemplate>

    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Note that you must not repeat the <table>in your <ItemTemplate>and to use single quotes when you need to put your Evalinside an attribute.

请注意,当您需要将您的属性放入属性时,您不能<table>在您的<ItemTemplate>and 中重复使用单引号Eval