Determine the repeater row count in asp.net

我与影子孤独终老i 提交于 2019-12-08 17:24:54

问题


How i can determine the amount of rows which display in this repeater at once?

<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>

回答1:


After doing lots of google, i finally got the answer: ((yourDataSourceDataType)rpttags.DataSource).count

Where rpttags is the ID of your repeater.

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




回答2:


This should work too:

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




回答3:


I just use <%# Container.ItemIndex %> to determine the row index.

Here is an example to use it with a bootstrap nested accordion.

Without the index, all the child accordions would open up if you click on one of their <a> elements.

<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>


来源:https://stackoverflow.com/questions/5999825/determine-the-repeater-row-count-in-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!