Forums

This topic is locked

Delete by check boxes with edit on same page

Posted 13 Feb 2004 20:57:14
1
has voted
13 Feb 2004 20:57:14 Greg LeBreck posted:
In asp with a sql db

I want to build a page that has a repeated region displaying stuff in a db and diplays a link to edit and a checkbox to delete a row item.

I can build it to the point of the display and haveing an edit link for each thing display, but I now want to add a checkbox next to everyline and hav a button at the bottom to delete the boxes which are checked

Replies

Replied 24 Feb 2004 14:29:10
24 Feb 2004 14:29:10 Vince Baker replied:
You need a bit of code that allows a multiple delete....I have posted some code below that will do this.

Basically, you need to add the checkbox and the bind the records unique id to id. THe whole table including the repeat region must be inside a form. When you click on the submit button direct your form to the page containing the code I will give you and ensure that you use the Get Method.

In the newly created page, change the names of fields, tables and connections to match your site .

----------------------------------


<!--Insert your connection string here -->

<% dim num

dim xide

dim whr

dim sql

whr=""

xide=split(request.querystring("checkbox",",",-1,1)

for each num in xide

if whr<>"" then whr=whr & " or "

whr=whr & "FIELD_ID=" & num

next

sql="DELETE FROM Table_Name WHERE "

sql=sql & whr %>

<%
set DeleteRecords = Server.CreateObject("ADODB.Command"
DeleteRecords.ActiveConnection = MM_CONN_NAME_STRING
DeleteRecords.CommandText = sql
DeleteRecords.CommandType = 1
DeleteRecords.CommandTimeout = 0
DeleteRecords.Prepared = true
DeleteRecords.Execute()
%>


<%
Dim strPreviousPage
strPreviousPage = Request.ServerVariables("HTTP_REFERER"
Response.Redirect(strPreviousPage)
%>



Good Luck and email me if you have any problems.

Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting

Reply to this topic