我正在使用asp classic构建一个网页,并使用每行末尾的删除按钮将mdb填充到html中。单击删除按钮时,正在删除数据库条目,但html表未重新加载并反映数据更改。如何在单击删除按钮时实现这一点?这是我的代码:
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include virtual="/adovbs.inc"-->
<HTML>
<%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\Inetpub\wwwroot\Scott1\EmployeeDB.mdb"
objConn.Open
Dim objRS
Set objRS = Server.CreateObject ("ADODB.RecordSet")
objRS.Open "Employee", objConn, , adLockOptimistic, adCmdTable
%>
<FORM METHOD=POST ACTION="default.asp">
<TABLE>
<tr><td>First Name:</td><td><INPUT TYPE=INPUT NAME="FirstName"></td></tr>
<tr><td>Last Name:</td><td><INPUT TYPE=INPUT NAME="LastName"></td></tr>
<tr><td>Employee ID:</td><td><INPUT TYPE=INPUT NAME="EmployeeID"></td></tr>
<TR><TD><INPUT TYPE=SUBMIT NAME=ADD VALUE="Add"></td></tr>
<%
objRS.AddNew
objRS("FirstName") = Request.Form("FirstName")
objRS("LastName") = Request.Form("LastName")
objRS("EmployeeID") = Request.Form("EmployeeID")
objRS.Update
%>
</TABLE>
</FORM>
<FORM METHOD=POST ACTION="default.asp">
<TABLE BORDER=2 WIDTH=500>
<TR BGCOLOR='#f8f8f8'>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Employee ID</TD>
<TD>Delete</TD>
</TR>
<%
Do While Not objRS.EOF
Response.Write "<TR><TD>" & objRS("FirstName") & "</TD>"
Response.Write "<TD>" & objRS("LastName") & "</TD>"
Response.Write "<TD>" & objRS("EmployeeID") & "</TD>"
Response.Write "<TD><INPUT TYPE=SUBMIT NAME=Delete VALUE=Delete >" & objRS.Delete & "</TD></TR>"
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</table>
</FORM>
</HTML>
答案 0 :(得分:0)
可能最简单的方法是根据当前记录的id给每个<tr>
一个id,然后使用JavaScript发布到删除例程(将保存在单独的ASP文件中),然后隐藏通过更改style.display
。
<tr id="row<%= rs("recordId") %>>
<td>...</td>
<td>...</td>
<td>
<input type="button" value="Delete" OnClick="deleteRow(<%= rs("recordId") %>);"
</td>
</tr>
JavaScript可能就像......
var xmlhttp;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari...
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
function ajaxPage(postPage, paramList) {xmlhttp.open("POST",postPage,false);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(paramList);return xmlhttp.responseText;}
function deleteRow(id) {
ajaxPage("deleteFunctionPage.asp", "id=" + id);
document.getElementById("row" + id).style.display = "none";
}