简体   繁体   English

中继器控制-如何每隔x行将其添加到项目模板?

[英]Repeater control - how to add to the item template every x rows?

I have a repeater control outputting some HTML. 我有一个中继器控件输出一些HTML。 I want a table which outputs 4 columns and then start a new row (each column will be the next item in the data set). 我想要一个输出4列的表格,然后开始一个新行(每列将是数据集中的下一项)。

I can do this with inline statements: 我可以使用内联语句来做到这一点:

<%  if ((i + 1) % 4 == 0 && i > 0)
                { //5 items per row%>
            </tr>
            <% } %>

But I can't seem to initialise i within the repeater control. 但是我似乎无法在转发器控件中初始化我。 Any ideas? 有任何想法吗?

I am using a repeater control because I have implemented pagination as a gridview was not appropriate due to how I am displaying the content. 我使用中继器控件是因为由于实现内容显示的方式,我已实现了分页,因为gridview不适合。

Depending on exactly what you are looking at doing you could work with a counter that exists and update it on every loop, handling the "ItemDataBound" event of the repeater control. 根据所要执行的操作,可以使用存在的计数器并在每个循环中对其进行更新,从而处理转发器控件的“ ItemDataBound”事件。 However, determining the "last" entry will be a bit more difficult, but possible. 但是,确定“最后一个”条目将更加困难,但是可能的。

However, I think a more appropriate option for you is to use a DataList rather than a repeater, as the data list can automatically render 4 columns and it will handle all of the HTML rendering for you. 但是,我认为对您来说更合适的选择是使用DataList而不是Repeater,因为数据列表可以自动呈现4列,它将为您处理所有HTML呈现。

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

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