Click to See Complete Forum and Search --> : Help with ASP/VBScript


Legun
10-23-2006, 01:39 PM
I am trying to add a line break instead of exit (if lPage >= 30 then exit for) where this line appears in my code, basiclly I have 1000's of entries that pull back from a database and the pagination scrolls way off the pages to the right, I want to say after 30 to break into a new line.

Here is the code from that area:

<%
Dim lPage
Dim lStart
Dim lEnd

For lPage = 1 To lMaxPages
lStart = (lPage * lPageSize) - (lPageSize - 1)
lEnd = lStart + (lPageSize - 1)

If (lEnd > lMaxRecords) Then lEnd = lMaxRecords

If (CInt(lPage) = CInt(lMyPage)) Then
Response.Write("<td class = ""alt2""><span class = ""smallfont"" title = ""Showing results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><strong><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</strong></span></td>")
Else
Response.Write("<td class = ""alt1""><span class = ""smallfont"" title = ""Show results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</span></td>")
End If

'*************** Add this line below here ******************

if lPage >= 30 then exit for

'*************** Add this line above here ******************

Next
%>

russell
10-23-2006, 06:57 PM
if lPage Mod 30 = 0 then Response.Write "<br>" & vbCrLf

Legun
10-24-2006, 08:04 AM
Thanks Russell but that didn't work either. My code look like this with your change but still no luck.


<%
Dim lPage
Dim lStart
Dim lEnd

For lPage = 1 To lMaxPages
lStart = (lPage * lPageSize) - (lPageSize - 1)
lEnd = lStart + (lPageSize - 1)

If (lEnd > lMaxRecords) Then lEnd = lMaxRecords

If (CInt(lPage) = CInt(lMyPage)) Then
Response.Write("<td class = ""alt2""><span class = ""smallfont"" title = ""Showing results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><strong><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</strong></span></td>")
Else
Response.Write("<td class = ""alt1""><span class = ""smallfont"" title = ""Show results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</span></td>")
End If

'*************** Add this line below here ******************

if lPage Mod 30 = 0 then Response.Write "<br>" & vbCrLf

'*************** Add this line above here ******************

Next
%>

russell
10-24-2006, 02:16 PM
you just need <tr> tags

Dim lPage
Dim lStart
Dim lEnd

Response.Write "<table>" & vbCrLf
For lPage = 1 To lMaxPages
Response.Write "<tr>" & vbCrLf
lStart = (lPage * lPageSize) - (lPageSize - 1)
lEnd = lStart + (lPageSize - 1)

If (lEnd > lMaxRecords) Then lEnd = lMaxRecords

If (CInt(lPage) = CInt(lMyPage)) Then
Response.Write("<td class = ""alt2""><span class = ""smallfont"" title = ""Showing results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><strong><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</strong></span></td>")
Else
Response.Write("<td class = ""alt1""><span class = ""smallfont"" title = ""Show results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</span></td>")
End If
Response.Write "</tr>" & vbCrLf

Next
Response.Write "</table>" & vbCrLf

Legun
10-24-2006, 02:27 PM
Thanks Russell for all your help, it worked like you said but I think the code is making it break into a new <tr> after every number now. I would like for it to break after every 30 numbers are written.

I appreciate all your help...

russell
10-24-2006, 02:29 PM
Dim lPage
Dim lStart
Dim lEnd

Response.Write "<table>" & vbCrLf
For lPage = 1 To lMaxPages
If lPage Mod 30 = 0 Then Response.Write "<tr>" & vbCrLf
lStart = (lPage * lPageSize) - (lPageSize - 1)
lEnd = lStart + (lPageSize - 1)

If (lEnd > lMaxRecords) Then lEnd = lMaxRecords

If (CInt(lPage) = CInt(lMyPage)) Then
Response.Write("<td class = ""alt2""><span class = ""smallfont"" title = ""Showing results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><strong><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</strong></span></td>")
Else
Response.Write("<td class = ""alt1""><span class = ""smallfont"" title = ""Show results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</span></td>")
End If
If lPage Mod 30 = 0 Then Response.Write "</tr>" & vbCrLf

Next
Response.Write "</table>" & vbCrLf

Legun
10-24-2006, 02:37 PM
Any chance I could send you an email with a screen shot. Worked great, but...

1-34 on one row
35 on next row
36-66 on next row

I changed the number to 35 instead of 30...

Any other ideas?

russell
10-24-2006, 03:09 PM
because lPage starts at 1 instead of 0. try if lPage mod 30 = 1. can post screenshot here to forum

Legun
10-24-2006, 03:42 PM
I submitted a screen shot, with changing 0 to 1.

etylocus
10-25-2006, 07:03 AM
There's an error in Russel's (almost) perfect code.Make the following change:

Dim lPage
Dim lStart
Dim lEnd

Response.Write "<table>" & vbCrLf
For lPage = 1 To lMaxPages
'If we're at the beggining of the row, we start a table row
If lPage Mod 30 = 1 Then Response.Write "<tr>" & vbCrLf
lStart = (lPage * lPageSize) - (lPageSize - 1)
lEnd = lStart + (lPageSize - 1)

If (lEnd > lMaxRecords) Then lEnd = lMaxRecords

If (CInt(lPage) = CInt(lMyPage)) Then
Response.Write("<td class = ""alt2""><span class = ""smallfont"" title = ""Showing results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><strong><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</strong></span></td>")
Else
Response.Write("<td class = ""alt1""><span class = ""smallfont"" title = ""Show results " & lStart & " to " & lEnd & " of " & lMaxRecords & """><a href = ""javascript:GotoPage(" & lPage & ");"">" & lPage & "</span></td>")
End If
'And we close the table row only at the end of the row
If lPage Mod 30 = 0 Then Response.Write "</tr>" & vbCrLf

Next
Response.Write "</table>" & vbCrLf

With that small change, it should work.
Small tip: when something doesn't look in screen as it should, check the HTML.
The HTML generated with the previous code wasn't valid, because the opening and closing tags were missing from the rows (<tr>'s & </tr>'s) that had mor than 1 cell. From there i was able to pinpoint the error in the code.
I usually use Firefox, that has this neat feature "View selection source" when you select some text on screen. And try to add carriage returns, specially after cells in tables, that makes for code readability when looking at raw HTML.

russell
10-25-2006, 07:14 AM
good call etylocus

Legun
10-25-2006, 08:01 AM
I would like to Thank You both for your help. It is great to see that there are professionals willing to help other professionals with their coding problems.

I will be sure to Pay It Forward!

And yes it does work perfect now! :)