Number Count Beside Each Record
Ultradev: ASP/vbscript
Question:
How do I display the number count beside each record?
i.e.
1. record 1
2. record 2
3. record 3
4. record 4
etc.
Issue:
Often times developers would like to display the real number count beside each record. One cannot use the Record ID because it usually doesn't reflect the real order of the record in the list.
Answer:
Assuming you have applied a repeat region behavior to your dynamic text. We will now adjust the behavior to enable you to display the count beside the record with this simple code:
<%=i %>
Here is a sample of the code UD generates surrounding the dynamic recordset text after applying the repeat region behavior:
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<%=(Recordset1.Fields.Item("ColumnName").Value)%> <br>
<%
repeat1__index="Repeat1__index"+1
repeat1__numrows="Repeat1__numRows"-1
Recordset1.MoveNext()
Wend
%>
Add the following variables to this code to display the count:
<%
Dim i
i = 1
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<%=(Recordset1.Fields.Item("ColumnName").Value)%> <%=i %> <br>
<%
repeat1__index="Repeat1__index"+1
repeat1__numrows="Repeat1__numRows"-1
i = i + 1
Recordset1.MoveNext()
Wend
%>
Note: The code <%= i %> should be within the repeat region.
Happy Programming!
Regards,
Omar
UDnewbie.com
Comments
Omar's, "Number Count Beside Each Record", used w/ Thomas Muck's, "Recordset Navigation Suite" extension
Recordset Navigation extension (ie. Links List: 1-10 | 11-20 | 21-30 | 31-40
Pages List: 1 | 2 | 3 | 4
Navigation Links: First | Previous | Next | Last )
<%dim offset
offset = request.querystring("offset")
%>
<%dim i
if offset = "" or offset = "0" then
i = 1
else
i = offset+1
end if
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<%=i %> <%=(Recordset1.Fields.Item("ColumnName").Value)%> <br>
<%
repeat1__index="Repeat1__index"+1
repeat1__numrows="Repeat1__numRows"-1
i = i + 1
Recordset1.MoveNext()
Wend
%>
Number Count beside Each Record
This is just what I was looking for, however I cannot get the code to start at "1" instead of it starting at "0". Also, when I add the code to the location displayed in the article, my page will not run. Any suggestions??
<%
Dim i
i = 1
%>
Great Work
PHP?
This is cool, what about a PHP version?
Getting this code to work in PHP is not that easy, any ideas?
You must me logged in to write a comment.