It has always been a headache for programmers to display images dynamically with line breaks in ASP. The current site is organized as follows:
The file description temp.mdis the name of the Data Warehouse. There are three tables on the side, respectively, title,20020.2310.shtml
Listpicture. asp multi-row, multi-Column Display of images
Listpicture2.asp multi-row, multi-Column Display of images, and display by PAGE
The following is a code snippet: <HTML>
<Head>
<Title> show images in multiple rows and columns </title>
</Head>
<Body>
<H2 align = "center"> show images in multiple rows and columns </H2>
<Table border = "0" width = "90%" align = "center">
<%
Dim DB
Set DB = server. Createobject ("ADODB. Connection ")
DB. Open "DBQ =" & server. mappath ("Temp. mdb") & "; driver = {Microsoft Access Driver (*. mdb )};"
'Create A recordset object
Dim strsql, RS
Strsql = "select * From picture"
Set rsmongodb.exe cute (strsql)
Dim J
J = 0' this variable is used to determine whether to change the next line
Response. Write "<tr>" 'here, You can output the mark for starting a new line.
Do while not Rs. EOF
J = J + 1
'The following lines output a cell, showing the thumbnail of the image and the title of the image.
Response. Write "<TD align = 'center'>"
Response. write "<a href = 'photo/" & RS ("2001000000002310.shtml ") & "'target = '_ blank'> </a>"
Response. Write "<br>" & RS ("title ")
Response. Write "</TD>"
'(J mod 3) indicates the remainder obtained by dividing I by 3. If it is 0, it indicates that it needs to be displayed in the next line.
If (J mod 3) = 0 then
Response. Write "</tr> <tr>" '</tr> ends the row and <tr> starts the next row.
End if
Rs. movenext
Loop
%>
</Table>
</Body>
</Html>
The following code snippet is listpicture2.asp:
<HTML>
<Head>
<Title> show image </title>
</Head>
<Body>
<H2 align = "center"> show images in multiple rows and columns </H2>
<%
'The following page_no variable is used to determine the page number of data displayed. If this is the first time you start the page, set it to 1. Otherwise, the parameter page_no is returned.
Dim page_no
If request. querystring ("page_no") = "" then
Page_no = 1
Else
Page_no = CINT (request. querystring ("page_no") 'Here, use CINT to convert it to an integer.
End if
'Timeout '-------------------------------------------------------------------------------------------
%>
<Center>
<Table border = "0" width = "90%">
<%
Dim DB
Set DB = server. Createobject ("ADODB. Connection ")
DB. Open "DBQ =" & server. mappath ("Temp. mdb") & "; driver = {Microsoft Access Driver (*. mdb )};"
'Create A recordset object
Set rs = server. Createobject ("ADODB. recordset ")
Strsql = "select * From picture"
Rs. Open strsql, DB, 1' use the keyboard pointer because it needs to be displayed by page.
'Query the record below. If it is not empty, the record is displayed.
If not Rs. bof and not Rs. EOF then
'The following is mainly for paging display
Rs. pagesize = 9' set to display 6 records per page
Dim page_total 'defines the total number of page Variables
Page_total = Rs. pagecount ': the total number of pages returned. this parameter is used when the following data page is output.
Rs. absolutepage = page_no 'sets the page number currently displayed. The passed page_no is used here.
'The following section uses the table to display all records on the current page
Dim I, j
I = Rs. pagesize 'variable I is used to control the display of the current page record. Note that this variable must be consistent with Rs. pagesize.
J = 0' variable J is used to control the display of three records per line
Response. Write "<tr>" 'here, You can output the mark for starting a new line.
Do while not Rs. EOF and I> 0' loops until the end of the current page or the end of the file
I = I-1 'Each display, I minus 1, when it becomes 0, indicates the end of the page
J = J + 1
'The following lines output a cell, showing the thumbnail of the image and the title of the image.
Response. Write "<TD align = 'center'>"
Response. write "<a href = 'photo/" & RS ("2001000000002310.shtml ") & "'target = '_ blank'> </a>"
Response. Write "<br>" & RS ("title ")
Response. Write "</TD>"
'Three images are required to be displayed in each row. (J mod 3) represents the remainder obtained by dividing I by 3. If it is 0, it indicates that the remainder must be displayed in the next row.
'Output </tr> tag to end the row. Output <tr> tag to start the next new row.
If (J mod 3) = 0 then
Response. Write "</tr> <tr>"
End if
Rs. movenext
Loop
End if
%>
</Table>
<%
'Timeout '--------------------------------------------------------------------------------------
'The output page number information, from 1 to the total page number page_total. Page_total is determined by the page display above.
Response. Write "<p> total" & page_total & "page ,"
Response. Write "current display" & page_no & "page ,"
Response. Write "select the data page :"
For I = 1 to page_total
%>
<A href = "listpictureb. asp? Page_no = <% = I %> "> <% = I %> </a>
<%
Next
%>
</Center>
</Body>
</Html>