使用中继器的水平表

发布于 2024-11-27 09:59:08 字数 1821 浏览 3 评论 0原文

我正在尝试使用中继器获取下表。

<table>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
</table>

但我不知道该怎么做。我尝试了以下方法:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
    </HeaderTemplate>
        <ItemTemplate>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </ItemTemplate>
        <SeparatorTemplate>
            </tr><tr>
        </SeparatorTemplate>
        <AlternatingItemTemplate>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </tr>
        </table>
    </FooterTemplate>
</asp:Repeater>

如果最后应用分隔符模板,效果会很好。 那么,使用每个数据项的单独表来使此模式发挥作用的唯一方法是吗?或者有什么方法可以使用一张桌子来实现我的目标?

I'm trying to get the following table using a repeater.

<table>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
</table>

But I can't work out how to do it. I have tried the following:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
    </HeaderTemplate>
        <ItemTemplate>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </ItemTemplate>
        <SeparatorTemplate>
            </tr><tr>
        </SeparatorTemplate>
        <AlternatingItemTemplate>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </tr>
        </table>
    </FooterTemplate>
</asp:Repeater>

And it would work great if the separator template was just applied at the end.
So is the only way to get this pattern to work using individual tables for each dataitem? Or is there a way I accomplish my goal using one table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

相思碎 2024-12-04 09:59:08

您可以尝试在 HeaderTemplate 中写入表的标题,在 ItemTemplate 中写入行;-)

编辑:首先,我认为您只希望标题位于标题中,每行代表数据项。因此,我建议使用以下代码:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </tr>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

现在,在您发表评论说要在每个数据项上方重复标题后,我建议如下:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
            </tr>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

注意:<您使用的 code>AlternatingItemTemplate 也代表一个数据项。通过使用此功能,您有机会以不同的方式显示每个项目的数据项(通常您对奇数行号和偶数行号使用不同的背景颜色)

编辑 2:
我希望,这次我正确理解了这个问题:-)

<asp:Repeater ID="rptGames" runat="server" OnItemCreated="rptGames_ItemCreated">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
            </tr>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
        </ItemTemplate>
        <AlernatingItemTemplate>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </AlernatingItemTemplate>

</asp:Repeater>

并且在后面的代码中(在 rptGames_ItemCreated 中),您可以根据数据项的数量设置页脚的模板 < ;/table>
注意:我没有测试过这个

You could try to write the header of the table in the HeaderTemplate and the rows in the ItemTemplate ;-)

Edit: First, I thought you want your titles in the header only and each line represents on data item. So I suggested the following code:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </tr>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Now, after your comment that you want to repeat the header above every single data item, I'd suggest the following:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
            </tr>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Note: The AlternatingItemTemplate that you used, represents a data item as well. By using this, you have the opportunity to display data items in different ways for every single item (normally you use different background colors for odd and even row numbers)

Edit 2:
I hope, I unterstood the question correctly this time :-)

<asp:Repeater ID="rptGames" runat="server" OnItemCreated="rptGames_ItemCreated">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
                <td>Description:</td>
                <td>Start time:</td>
                <td>End time:</td>
                <td>Game type:</td>
            </tr>
            <tr>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
        </ItemTemplate>
        <AlernatingItemTemplate>
                <td><%# Eval("Description") %></td>
                <td><%# Eval("StartTime") %></td>
                <td><%# Eval("EndTime") %></td>
                <td><%# Eval("GameType") %></td>
            </tr>
        </AlernatingItemTemplate>

</asp:Repeater>

And in code behind (in rptGames_ItemCreated ), you could set the template of the footer depending on the count of your data items to </table> or </tr></table>
Note: I haven't tested this

乞讨 2024-12-04 09:59:08

将表格标题行移至标题,并将每个项目封装在 tr 中

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </tr>
    </HeaderTemplate>
        <ItemTemplate>
           <tr>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
           </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Move your table header row to the header and each of your item encapsulated in a tr

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
            <td>Description:</td>
            <td>Start time:</td>
            <td>End time:</td>
            <td>Game type:</td>
        </tr>
    </HeaderTemplate>
        <ItemTemplate>
           <tr>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
           </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
甜心小果奶 2024-12-04 09:59:08

尝试像这样:

更新:要重复标题(根据OP的评论),请像这样修改它(在每个trtd) > 如果您想要更多列):

注意: 假设OP想要以不同的方式设置标题样式,添加背景颜色(只是为了给出一个想法)。

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr style="background-color: whiteSmoke">
              <td>Description:</td>
              <td>Start time:</td>
              <td>End time:</td>
              <td>Game type:</td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
          </tr>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Try it like this:

Update: To repeat the headers (as per OP's comment), modify it like this (add more tds into each tr if you want more columns):

Note: Assuming that OP wants to style the headers differently, added a background color (just to give an idea).

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
            <tr style="background-color: whiteSmoke">
              <td>Description:</td>
              <td>Start time:</td>
              <td>End time:</td>
              <td>Game type:</td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
          </tr>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
岛歌少女 2024-12-04 09:59:08

您需要将 放入项目模板(以及交替项目模板)(而不是标题)中。

<ItemTemplate>
<tr>
   <td>Description:</td>
   <td>Start time:</td>
   <td>End time:</td>
   <td>Game type:</td>
</tr>
</ItemTemplate>

然后调整您的分隔符模板:

<SeparatorTemplate>
   <tr></tr>
</SeparatorTemplate>

You need to put the <tr> in your item template (and also the alternating item template) (not the header).

<ItemTemplate>
<tr>
   <td>Description:</td>
   <td>Start time:</td>
   <td>End time:</td>
   <td>Game type:</td>
</tr>
</ItemTemplate>

Then adjust your seperator template:

<SeparatorTemplate>
   <tr></tr>
</SeparatorTemplate>
兮颜 2024-12-04 09:59:08

试试这个:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
          <tr>
              <th>Description:</th>
              <th>Start time:</th>
              <th>End time:</th>
              <th>Game type:</th>
              <th>Description:</th>
              <th>Start time:</th>
              <th>End time:</th>
              <th>Game type:</th>
            </tr>
          <tr> 
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
          </tr>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

我的示例中唯一的问题是,如果记录数不是偶数,则不会打印结束,并且表格可能会丢失重击。我确信您可以在后面的代码中检查这一点并为此添加一个技巧。也许是一个可以在运行时修改的literal

更新

该代码应生成以下包含 6 条记录的结果:

<table>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
</table>

Try this out:

<asp:Repeater ID="rptGames" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
        <ItemTemplate>
          <tr>
              <th>Description:</th>
              <th>Start time:</th>
              <th>End time:</th>
              <th>Game type:</th>
              <th>Description:</th>
              <th>Start time:</th>
              <th>End time:</th>
              <th>Game type:</th>
            </tr>
          <tr> 
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <td><%# Eval("Description") %></td>
            <td><%# Eval("StartTime") %></td>
            <td><%# Eval("EndTime") %></td>
            <td><%# Eval("GameType") %></td>
          </tr>
        </AlternatingItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

The only issue I have with my example is that if there is not an even number of records, then the closing</tr> won't be printed and the table might get out of whack. I'm sure you can check for that in the code behind and add a hack for that. Maybe a literal that you can modify at run-time?

UPDATE

That code should produce the following results with six records:

<table>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
    <tr>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
        <td>Description:</td>
        <td>Start time:</td>
        <td>End time:</td>
        <td>Game type:</td>
    </tr>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
        <td>Data4</td>
    </tr>
</table>

.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文