?? index.asp
字號(hào):
<% Option Explicit %>
<!--#Include File="odbc_connection.asp"-->
<!--#Include File="config.asp"-->
<HTML>
<head>
<title><%=GuestTitle%></title>
<link rel="stylesheet" href="guest.css">
<script language="JavaScript">
<!--
//函數(shù)check_Null用來(lái)進(jìn)行客戶端驗(yàn)證
function check_Null(){
if (document.form1.title.value==""){
alert("主題不能為空!");
return false;
}
if (document.form1.name.value==""){
alert("姓名不能為空!");
return false;
}
if (document.form1.title.value.length>100){
alert("主題不能超過(guò)100個(gè)字符");
return false;
}
if (document.form1.name.value.length>30){
alert("姓名不能超過(guò)30個(gè)字符");
return false;
}
return true;
}
// -->
</script>
</head>
<body >
<!--注釋:下面要從配置文件中讀取常量GuestTitle-->
<h1 align="center"><%=GuestTitle%></h1>
<!--注釋:下面是提交留言表單,單擊提交按鈕后,首先會(huì)調(diào)用上面的客戶端驗(yàn)證函數(shù)驗(yàn)證,
驗(yàn)證通過(guò)后,再傳送到add.asp,添加完畢后,重定向回本頁(yè)面-->
<form method="post" action="add.asp" name="form1" onsubmit="javascript: return check_Null();">
<table border="0" width="80%" bgcolor="#203F80" align="center">
<tr>
<td><font color="white">主題:</font></td>
<td><input type="text" name="title" size="60">** </td>
</tr>
<tr>
<td><font color="white">內(nèi)容:</font></td>
<td><Textarea Name="body" Rows="4" Cols="60"></TextArea></td>
</tr>
<tr>
<td><font color="white">姓名:</font></td>
<td><input type="text" name="name" size="13">** </td>
</tr>
<tr>
<td><font color="white">email:</font></td>
<td><input type="text" name="email" size="40"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" 提 交 " Size="20" ></td>
</tr>
</table>
</form>
<p>
<%
'----------------------------------------------------------------------------------
'以下開始顯示原有留言
Dim rs,strsql
'建立Recordset對(duì)象,因?yàn)橐猪?yè)顯示數(shù)據(jù),所以請(qǐng)注意Open方法的參數(shù)
Set rs=Server.CreateObject("ADODB.Recordset")
strsql ="Select * From guest Order By Submit_date Desc"
rs.Open strsql,db,1
'如果記錄集是空的,就停止運(yùn)行程序,如果非空,就分頁(yè)顯示
If rs.Bof Or rs.Eof Then
Response.Write "<p align='center'>暫時(shí)沒有留言"
Response.End
Else
'下面一段判斷當(dāng)前顯示第幾頁(yè)
Dim page_no
If Session("page_no")="" Then
'如是第一次打開,為1
page_no=1
Session("page_no")=page_no
Elseif Request.QueryString("page_no")<>"" Then
'如果選擇了頁(yè)碼,就令其為指定頁(yè)碼
page_no=Cint(Request.QueryString ("page_no"))
Session("page_no")=page_no
Else
'其它情況下,則從Session中讀取原來(lái)的頁(yè)碼
page_no=Session("page_no")
End If
'下面一段開始分頁(yè)顯示,指向要顯示的頁(yè),然后逐條顯示當(dāng)前頁(yè)的所有記錄。
rs.PageSize=PageSize '從config.asp讀取參數(shù)設(shè)置,每頁(yè)顯示多少條
rs.AbsolutePage=page_no '設(shè)置當(dāng)前顯示第幾頁(yè)
Dim I '該變量用來(lái)控制顯示當(dāng)前頁(yè)記錄
I=rs.PageSize
Do While Not rs.Eof And I>0 '循環(huán)直到當(dāng)前頁(yè)結(jié)束或記錄集結(jié)尾
I=I-1
%>
<TABLE border="0" bordercolor="#8800FF" width="80%" align="center">
<tr>
<td colspan=2><hr></td>
</tr>
<tr>
<td width=20%>主題</td>
<td><%=rs("title")%></td>
</tr>
<tr>
<td>內(nèi)容</td>
<td><%=rs("body")%></td>
</tr>
<tr>
<td>留言人</td>
<td>
<a href="mailto:<%=rs("email")%>"><small><font color="#000000"><%=rs("name")%></font></small></a>  <%=rs("submit_date")%>
<%
Response.Write "<a href='delete.asp?id=" & rs("id") & "' ><small>刪除</small></a>"
%>
</td>
</tr>
<tr>
<td>
<%
Response.Write "<a href='readd.asp?id=" & rs("id") & "&title=" & rs("title") & "' ><small>回復(fù)</small></a>"
%>
</td>
<td>
<% Response.Write rs("reback") %>
</td>
</tr>
</TABLE>
<%
rs.MoveNext
Loop
'下面一段在下方顯示頁(yè)數(shù)信息,從1到總頁(yè)數(shù)循環(huán),如不是當(dāng)前頁(yè),就加上超鏈接
Response.Write "<p align='center'>請(qǐng)選擇數(shù)據(jù)頁(yè): "
For I=1 To rs.PageCount
If I=page_no Then '如是當(dāng)前頁(yè),就不加超鏈接
Response.Write I & " "
Else '如不是當(dāng)前頁(yè),就加上超鏈接
Response.Write "<a href='index.asp?page_no=" & I & "'>" & I & "</a> "
End If
Next
End If
'----------------------------------------------------------------------------------
%>
</body>
</html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -