删除数据库条目后重新加载html表数据 [英] reload html table data after database entry deleted

查看:18
本文介绍了删除数据库条目后重新加载html表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asp classic 构建网页,并将 mdb 填充到每行末尾带有删除按钮的 html 中.单击删除按钮时,正在删除数据库条目,但 html 表未重新加载并反映数据更改.单击删除按钮时,我怎样才能做到这一点?这是我的代码:

I am building a web page using asp classic and populating a mdb into an html with delete button at the end of each row. When the delete button is clicked the database entry is being deleted, but the html table is not reloading and reflecting the data change. How can I make that happen when the delete button is clicked? Here is my code:

<%@ 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:InetpubwwwrootScott1EmployeeDB.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>

推荐答案

可能最简单的方法是根据当前记录的 id 给每个 <tr> 一个 id 然后使用 JavaScript发布到删除例程(将保存在单独的 ASP 文件中),然后通过更改 style.display 隐藏该行.

Probably the easiest way would be to give each <tr> an id based on the id of the current record then use JavaScript to post to the delete routine (which will be held in a separate ASP file), then hide the row by changing the style.display.

<tr id="row<%= rs("recordId") %>>
    <td>...</td>
    <td>...</td>
    <td>
        <input type="button" value="Delete" OnClick="deleteRow(<%= rs("recordId") %>);"
    </td>
</tr>

JavaScript 可能类似于...

And the JavaScript could be something like...

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";
}

这篇关于删除数据库条目后重新加载html表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆