开发者

Show/Split 4 rows in a table in Loop

The code below is how to show/split 2 rows in a table. But how do I get it to show/split it to 4 rows and not only two ???

dim bCloseRow
bCloseRow = True
Do while not objTrucks.eof
If bCloseRow Then response.write "<tr>"
bCloseRow = Not bCloseRow
response.write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") &a开发者_StackOverflow中文版mp; "</td>"
If bCloseRow Then response.write "</tr>"
objTrucks.movenext
loop

Thanks for any help.


If there are more rows then four in the recordset you have to make a row more. And if there is less then four you have to insert some empty td tags.

Hope this helps

   const iCols=4
    dim iCount:iCount=0
    if not objTrucks.eof then
        response.write "<table>"
        Do while not objTrucks.eof
            if iCount=0 then response.write "<tr>"
            response.write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") & "</td>"
            objTrucks.movenext
            iCount = iCount + 1
            if iCount=iCols then 
                response.write "</tr>"
                iCount=0
            end if
        loop
        if iCount>0 then
            for i = iCount to iCols-1
                response.write "<td></td>"
            next
            response.write "</tr>"
        end if
        response.write "</table>"
    end if


I would do this using a counter instead of a Boolean flag:

Const numCols = 4
Dim counter
counter = 0

Do While Not objTrucks.EOF
    If counter Mod numCols = 0 Then
        Response.Write "<tr>"
    End If

    counter = counter + 1

    Response.Write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") & "</td>"

    If counter Mod numCols = 0 Then
        Response.Write "</tr>"
    End If

   objTrucks.MoveNext
Loop
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜