【问题标题】:Determine the repeater row count in asp.net确定asp.net中的中继器行数
【发布时间】:2011-05-14 04:33:59
【问题描述】:

我如何确定一次在此转发器中显示的行数?

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="News" EnableViewState="true">
  <ItemTemplate>
    <hr />
    <div style="color:#036e90; font-weight: bold; font-family:Tahoma; text-align:center ; padding-left:10px"><a href="DisplayNews.aspx"><%#DataBinder.Eval(Container.DataItem, "News_Name")%></a></div>
                <div style=" FONT-SIZE: 10pt;  FONT-FAMILY: Tahoma ; text-align:center;padding-left:10px"><%#DataBinder.Eval(Container.DataItem, "News_Description")%></div>
    <br />
             <hr  />
  </ItemTemplate>
</asp:Repeater>

【问题讨论】:

  • 服务器端、客户端还是在每个项目上显示计数器编号?

标签: asp.net repeater


【解决方案1】:

这应该也可以:

((Container.Parent as Repeater).DataSource as IList).Count

【讨论】:

    【解决方案2】:

    我只是使用&lt;%# Container.ItemIndex %&gt; 来确定行索引。

    这是一个将它与引导嵌套手风琴一起使用的示例。

    如果没有索引,如果您单击其中一个 &lt;a&gt; 元素,所有子手风琴都会打开。

    <div id="accordion" class="mb-3">
      <div class="card eventAccordion closed">
        <div id="headingOne" class="card-header">
        </div>
        <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
          <div class="card-body" id="child1">
            <asp:Repeater runat="server" ID="myId">
              <ItemTemplate>
                <div class="card">
                  <div class="card-header">
                    <a href="#" class="btn-link d-inline-flex" data-toggle="collapse" data-target="#collapseOne<%# Container.ItemIndex %>">
                    </a>
                  </div>
                  <div class="card-body collapse" data-parent="#child1" id="collapseOne<%# Container.ItemIndex %>">
                  </div>
                </div>
              </ItemTemplate>
            </asp:Repeater>
          </div>
        </div>
      </div>
    </div>
    

    【讨论】:

      【解决方案3】:

      在google了很多之后,我终于得到了答案: ((yourDataSourceDataType)rpttags.DataSource).count

      其中 rpttags 是中继器的 ID。

      http://dotnetacademy.blogspot.com/2011/08/rowitem-count-in-repeater.html

      【讨论】:

        猜你喜欢
        • 2015-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多