Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkboxes

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
What would be the best way to delete multiple records using multiple checkboxes? I have looked on the web and stuff, and I am still not quite sure about checkboxes in ASP.

Thanks, Jason
 
Page 1

DIM deleteCount
deleteCount = 0
DO WHILE NOT rs.EOF
deleteCount = deleteCount + 1
%>
<input type=&quot;checkbox&quot; name=&quot;del_<%= deleteCount %>&quot; value=&quot;[PrimaryKey]&quot;>
<%
rs.MoveNext
LOOP
%>
<input type=&quot;hidden&quot; name=&quot;totalRecords&quot; value=&quot;<%= deleteCount %>&quot;>

Page 2

DIM i
FOR i = 1 TO Request.Form(&quot;totalRecords&quot;)
IF Request.Form(&quot;del_&quot; & i) <> &quot;&quot; THEN
sql = &quot;DELETE FROM Table WHERE [Primary Key] = &quot; & Request.Form(&quot;del_&quot; & i)
cn.Execute(sql)
END IF
NEXT
 
Or you could do this:
<form>
<input type=checkbox value=[primary key] name=pkey>[some filed here]<br>
<input type=&quot;submit&quot; value=&quot;Delete&quot;>
</form>

IN ASP CODE

<%
dim pkey
pkey = split(request.form(&quot;pkey&quot;),&quot;'&quot;)
for x = 0 to ubound(pkey)
sql = &quot;delete * from [my table] where primarykey=&quot; & pkey(x)
myconn.execute(sql)
next
%>

This is less code and less form fields to filter and account for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top