Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Classic ASP question

Reply
Thread Tools

Classic ASP question

 
 
Mike P
Guest
Posts: n/a
 
      08-06-2008
I have very little experience of Classic ASP, but I need to take some
data from a table, write it to the screen in a tabular format, show a
check box at the end of every row, and write some code to enable the
user to check all check boxes, and then some code to respond to a button
click to find out which rows were checked.

I know how to read data from a recordset and put it into a <table>
object, but the rest, particularly the check box bits, are giving me
problems. Can somebody please help me out?






*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Old Pedant
Guest
Posts: n/a
 
      08-06-2008
"Mike P" wrote:

> I have very little experience of Classic ASP, but I need to take some
> data from a table, write it to the screen in a tabular format, show a
> check box at the end of every row, and write some code to enable the
> user to check all check boxes, and then some code to respond to a button
> click to find out which rows were checked.


Well, the "check all check boxes" will be JavaScript code, in the browser,
nothing to do with ASP.

And you don't say *WHAT* the code that "respond[s] to a button click" is
supposed to do. Just say "You checked boxes 17, 33, and 42"??? Or delete
records from the DB? Or copy records?

In other words, does the response need to be JS in the browser or ASP code
on the server?

*ASSUMING* you mean that you want to (say) delete all the checked records,
it's pretty easy.

Since you give us so little info about your app, I'll make some simplistic
assumptions. I'm doing it all on one page. So the <form> submits back to
the same page and, if there are an records to be deleted, they are deleted.
Whether a delete occurred or not, all the non-deleted records are shown with
checkboxes.

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

If Trim( Request("DELETE") ) <> "" Then
' submit was pushed, delete all checked records
SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
howMany = -1
conn.Execute SQL, howMany
Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
End If
%>
<form method="POST">
<table border=1 cellpadding=5>
<%
SQL = "SELECT ID, Name, Address FROM people"
Set RS = yourAlreadyOpenConnection.Execute( SQL )
Do Until RS.EOF
%>
<tr>
<td><%=RS("Name")%></td>
<td><%=RS("Address")%></td>
<td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<input type=submit value="Delete checked people" name="DELETE">
</form>

And that's all there is to it. Presto.

p.s.: Assumes the the ID field is a numeric field. Minor change needed if
it's a text field.

 
Reply With Quote
 
 
 
 
Old Pedant
Guest
Posts: n/a
 
      08-06-2008
Oh, what the heck...

Here's the code for adding a "CHECK ALL" button:

<HTML>
<HEAD>
<SCRIPT>
function checkAll( cbs )
{
if ( cbs.length == null )
{
// if only one checkbox
cbs.checked = true;
return; // only one to do
}
for ( var c = 0; c < cbs.length; ++c )
{
cbs[c].checked = true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

If Trim( Request("DELETE") ) <> "" Then
' submit was pushed, delete all checked records
SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
howMany = -1
conn.Execute SQL, howMany
Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
End If
%>
<form method="POST">
<INPUT Type=Button Value="Check all" onClick="checkAll(this.form.ZAP);">
<table border=1 cellpadding=5>
<%
SQL = "SELECT ID, Name, Address FROM people"
Set RS = yourAlreadyOpenConnection.Execute( SQL )
Do Until RS.EOF
%>
<tr>
<td><%=RS("Name")%></td>
<td><%=RS("Address")%></td>
<td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<input type=submit value="Delete checked people" name="DELETE">
</form>
</BODY></HTML>

Should have mentioned that this is all off the top of my head, utterly
untested. But it's warranted against bugs, anyway!

Guaranteed to be free of carpenter ants and dung beetles for 30 picoseconds
or 30 picometers, whichever comes first.


 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      08-06-2008


"Old Pedant" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Oh, what the heck...
>
> Here's the code for adding a "CHECK ALL" button:
>
> <HTML>
> <HEAD>
> <SCRIPT>
> function checkAll( cbs )
> {
> if ( cbs.length == null )
> {
> // if only one checkbox
> cbs.checked = true;
> return; // only one to do
> }
> for ( var c = 0; c < cbs.length; ++c )
> {
> cbs[c].checked = true;
> }
> }
> </SCRIPT>
> </HEAD>
> <BODY>
> <%
> Set conn = Server.CreateObject("ADODB.Connection")
> conn.Open "...your connection string..."
>
> If Trim( Request("DELETE") ) <> "" Then
> ' submit was pushed, delete all checked records
> SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
> howMany = -1
> conn.Execute SQL, howMany
> Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
> End If
> %>
> <form method="POST">
> <INPUT Type=Button Value="Check all" onClick="checkAll(this.form.ZAP);">
> <table border=1 cellpadding=5>
> <%
> SQL = "SELECT ID, Name, Address FROM people"
> Set RS = yourAlreadyOpenConnection.Execute( SQL )
> Do Until RS.EOF
> %>
> <tr>
> <td><%=RS("Name")%></td>
> <td><%=RS("Address")%></td>
> <td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
> </tr>
> <%
> RS.MoveNext
> Loop
> %>
> </table>
> <input type=submit value="Delete checked people" name="DELETE">
> </form>
> </BODY></HTML>
>
> Should have mentioned that this is all off the top of my head, utterly
> untested. But it's warranted against bugs, anyway!
>


What happens if there no records and the user presses the button


--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
Old Pedant
Guest
Posts: n/a
 
      08-06-2008

"Anthony Jones" wrote:

> What happens if there no records and the user presses the button


Hey, that's what the warranty is for!!


 
Reply With Quote
 
Mike P
Guest
Posts: n/a
 
      08-07-2008
Thank you both for your help! What I was looking to do when submitting
the page is to add all the records that are checked to an array, because
I will need to pass the information to another page and then populate a
dropdown with the email addresses of all the people who were checked on
the previous page.

Cheers,

Mike


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Classic ASP to ASP.Net migration question Gary Morris ASP .Net 3 10-16-2004 11:44 PM
Newbie Question: Asp Classic and ASP.NET running on IIS5 side-by-side ? Bob [BVP] ASP .Net 5 08-09-2004 01:55 PM
LOOP through an ASP form's pages (not ASP.NET - ASP classic) David A. Beck ASP General 10 04-13-2004 05:38 PM
Re: Need to replicate Classic ASP functionality in ASP.NET using Datagrid Marina ASP .Net 2 01-07-2004 09:56 PM
Re: Classic ASP to ASP.Net XMLHTTP S. Justin Gengo ASP .Net 0 08-27-2003 04:29 PM



Advertisments