开发者

Access the first and/or last item in an bound ArrayList

I've got an ArrayList bound to a repeater control. In an associated, but separate, area of the page, I'd like to get the first and last item out of the bound control. It's actually a paging element to a table.

Here is the code for the Repeater:

this.Repeater1.DataSource = pagingArray;<br>
this.Repeater1.DataBind();<br>

<asp:Repeater id="Repeater1" runat="server"><br>
    <ItemTemplate><br>
        <a href="/?page=&lt;%# Container.DataItem %>"><%# Container.DataItem %?</a><br>
    </ItemTemplate><br>
</asp:Repeater><br>

I'd like to get the first element from this repeater and display it. The code that I have right now (that doesn't work) is:

开发者_JS百科
<% Response.Write(Repeater1.Items[0].ToString()); %>

BTW: I'm a complete .NET newb.

Thanks


Because your <% Response.Write(Repeater1.Items[0].ToString()); %> happens before you've bound the repeater. Why not read from the original data source, anyway?

<% Response.Write(this.pagingArray.First().ToString()); %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜