使用ASP为重复数据实现Rowspan

时间:2018-08-23 05:55:56

标签: html vbscript

我已存储过程产生以下结果:

Result from sp and also display in html table

目前,我正在使用ASP作为以下代码来显示html表;

if DBExecute(SQL,adoConn2,rsSQL,True) then
    while not rsSQL.eof
 <tr>
     <td>1st data</td>
     <td>2nd data</td>
     <td>3rd data</td>
     <td>4th data</td>
     <td>5th data</td>
 </tr>
    rsSQL.movenext
    wend
end i

问题是如何为表中的相同“第一数据”实现行跨度? 这样我的桌子应该看起来像这样;

---------------------------------
SCB0007091 | BCRP01 | 2 | 2 | 0 |
---------------------------------
SCB0007092 | EFFY   | 1 | 1 | 0 |
           ----------------------
           | BJGG01 | 5 | 5 | 0 |
           ----------------------
           | BSP401 | 3 | 3 | 0 |
---------------------------------
SCB0007093 | CGMO01 | 10| 10| 0 |

1 个答案:

答案 0 :(得分:1)

如评论中所述,您的SQL查询应按键列对数据进行排序。

<%
if DBExecute(SQL, adoConn2, rsSQL, True) then

    ' go through the table once and count how many times each key column value occurs
    rowspan = server.createobject("Scripting.Dictionary")
    while not rsSQL.eof
        key = rs!column1
        if not rowspan.exists(key) then rowspan.add(key, 0)  
        rowspan(key) = rowspan(key) + 1
        rsSQL.movenext
    wend

    ' reset the recordset and build the actual table
    rsSQL.movefirst
%>
    <table>
<%
    while not rsSQL.eof
        key = rs!column1
%>
        <tr>
<%    
        ' output the first <td> only once, with the correct rowspan
        if rowspan.exists(key) then
%>
            <td rowspan="<%=rowspan(key)%>"><%=server.htmlencode(key)%></td>
<%
            rowspan.remove(key)
        end if

        ' output remaining <td>s normally
%>
            <td><%=server.htmlencode(rsSQL!column2)%></td>
            <td><%=server.htmlencode(rsSQL!column3)%></td>
            <td><%=server.htmlencode(rsSQL!column4)%></td>
            <td><%=server.htmlencode(rsSQL!column5)%></td>
        </tr>
<%
        rsSQL.movenext
    wend
%>
    </table>
<%
end if
%>