ASP控製表格的行列來顯示資料

來源:互聯網
上載者:User
控制|資料|顯示     很多時候,我們在顯示資料庫的內容時,會用到幾行或幾列來顯示資料,如10條資料,要以每行2列或3列形式顯示。

下面是一個使用數組以表格顯示幾行幾列的簡單的示列代碼,希望對您有所協助。

<%
function tablebody(arr,cols,functionstr)
 'arr為數組
 'cols為列數
 'functionstr為輸出內容用的function,沒有為空白

 dim allnum,i,j
 allnum = ubound(arr)
 for i = 0 to (allnum/cols)
  Response.write (VbTab &"<tr>" & VbNewLine)
  for j = 0 to (cols-1)
   ij = (i*cols+j)
   Response.write (VbTab & VbTab &"<td width="""& formatnumber(100/cols,0) &"%"">")
   if ij <= allnum then
    if len(functionstr) > 0 then
     execute(""& functionstr &"(arr(ij))")
    else
     Response.write (arr(ij))
    end if
   else
    Response.write (" ")
   end if
   Response.write ("</td>" & VbNewLine)
  next
  Response.write (VbTab &"</tr>" & VbNewLine)
 next
end function

function test1(str)
 Response.write ("<div align=""center"">"& str &"</div>")
end function


'樣本1
dim kk(9)
for k = 0 to 9
 kk(k) = k+1
next
%>
<table border="1" width="600" cellpadding="2">
<%call tablebody(kk,1,"")%>
</table>
<hr>

<table border="1" width="600" cellpadding="2">
<%call tablebody(kk,4,"test1")%>
</table>
<hr>

<table border="1" width="600" cellpadding="2">
<%call tablebody(kk,5,"")%>
</table>
<hr>
<%
dim wwwstr,wwwarr
wwwstr = "51windows.Net|blueidea.com|google.com|yahoo.com|msn.com.cn|csdn.net|ipark.cn|1kg.cn"
wwwarr = split(wwwstr,"|")

function urltest1(str)
 Response.write ("<a href=""http://www."& str &""" target=""_blank"">"& str &"</a>")
end function

function urltest2(str)
 Response.write ("<button style=""width:100%;"" onclick=""window.open('http://www."& str &"','','')"">"& str &"</button>")
end function
%>
<table border="1" width="480" cellpadding="2">
<%call tablebody(wwwarr,3,"urltest1")%>
</table>
<hr>

<table border="2" width="480" cellpadding="2" cellspacing="2" >
<%call tablebody(wwwarr,4,"urltest2")%>
</table>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.