Thread: Asp Code help
View Single Post
Old 03-21-2003, 02:15 PM   #4 (permalink)
rdove
Masked Moderator
 
rdove's Avatar
 
Join Date: May 2002
Location: Indianapolis, IN
Posts: 260
rdove is on a distinguished road
Here is a good example of how I would go about deleting items checked. This example assumes that the value is a NUMBER, but you could change it to accept strings too.

First I generate a checkbox name based on "i" which corresponds to a autonumber record in the database. I could just use the value of the record itself, but the code I copied and pasted from will never have a record out of the autonumber order.

Next I send a couple values in the querystring and post the data back to the page. Then I use a loop to check each checkbox that I created on the page. Notice I send a value called num back to the page. This tells me exactly how many checkboxes I generated.

I doubt this code does everything you need it to, but it will set you in the correct direction.

Code:
<%

Dim RS, MyConn, SQL

Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "dsn=notreal"

if request("action") = "approve" then

 for i = 1 to request("num")

    if request.form("chk" & i) = "" & i then

      SQL = "DELETE FROM table WHERE ITEM1 = " & i
      MyConn.Execute(SQL)

    end if

  next

  response.redirect("page2.asp")

end if

%>


<form name="form1" method="post" action="page.asp?action=approve&num=<% response.write(rs.RecordCount) %>">
<% dim i
   i = 1
   While NOT rs.EOF 
%>
<input type="checkbox" name="chk<% response.write(i) %>" value="<% response.write (i) %>">

<% rs.MoveNext
   i = i + 1
   wend
   rs.close
   MyConn.close
   Set rs = Nothing
   Set MyConn = Nothing
%>
Hope this helps
__________________
~Ryan

rdove is offline   Reply With Quote