autonumber line in a repeater ?

L

Lee

Hi ;)

You could use the ItemDataBound event, which will fire once for each item
bound to the repeater, then just modify the item to include some
representation of the counter.

You could use a private field in the page class to hold the counter, reset
it to your initial value prior to calling DataBind then within the
ItemDataBound event, use the counter value and increment it.
 
T

TJS

not having much success here.
value displayed always equals total count instead of incremental step of 1


====================code======================
Dim vItemNumber As Integer = 0
......
Sub AutoNumber(o As Object, e As RepeaterItemEventArgs)
vItemNumber += 1
End Sub
.....

<asp:repeater id="items" runat="server" OnItemDataBound ="AutoNumber">

......

<ItemTemplate>
<tr class="rowcolor">
<td><%= vItemNumber %></td>
 
E

Eliyahu Goldin

This will certainly work. Only one comment. PreRender event suits the task
better since the repeater is fully build at this stage and you just loop
through the items.

Eliyahu
 
Joined
May 26, 2008
Messages
2
Reaction score
0
This doesn't work. With PreRender, it returns the first integer (1). With OnItemDataBound, it returns the last integer.

Instead, add this to your ItemTemplate:

<asp:Label ID="Label1" runat="server"><%# Convert.ToString(Container.ItemIndex + 1) %></asp:Label>

That produces a real integer count.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top