Determine the repeater row count in asp.net
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>
This should work too:
((Container.Parent as Repeater).DataSource as IList).Count
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
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>
精彩评论