Newbie: Count in Repeater

  • Thread starter Thread starter Singularity.co.uk
  • Start date Start date
S

Singularity.co.uk

Hi

I have a repeater on the page which is displaying data from the database
correctly. My question is how can I modify the following code to add an
increasing number value before the database record:

<asp:Repeater id="rptPoint" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ActionPoint") %>
</ItemTemplate>
</asp:Repeater>

At the moment my text comes back as:

Point1
Point2
Point3

Whereas i would like it coded so that it displays on the screen as:

1. Point1
2. Point2
3. Point3

If I was coding using classic asp, I would have added a count value and
displayed it in front of each point as follows:

<%
Dim PointCnt
PointCnt = 0
While Not rsRecordset.EOF
PointCnt = PointCnt + 1
Response.Write PointCnt & ". " &
rsRecordset.Fields.Item("PointValue").Value & "<br>"
rsRecordset.Movenext
Wend
%>

Any help is appreciated.

Thanks

Brendan
 
Hi,

Try this:
in the code behind:
protected int index=1;

in the aspx:
<%# ((i++).ToString() + DataBinder.Eval(Container.DataItem, "ActionPoint")
%>

A more cleaner solution:

in the code behind:
protected int index=0;

protected string FormatIt( string val )
{
index++;
return index.ToString() + " " + val;
}

in the aspx:
<%# FormatIt( DataBinder.Eval(Container.DataItem, "ActionPoint") ) %>


cheers,
 

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

Similar Threads

Nested Repeaters 1
Update in repeater 2
Hide / Show Panels through a Repeater 1
Repeater 5
Why image is not showing in repeater 1
Add new row to Repeater? 2
database sums. 1
Repeater Problem 1

Back
Top