Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2005, 12:50 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get rownumber of row from an html table

Hi,

I have an asp page which has a table populated by an ado recordset.
For each row generated in the html table a delete button is displayed
I need when hitting the delete button to pick the rownumber so that I
can send to my ado delete statement with the right where close (key).

Please see code below.

<% dim ofield1
set rs.open="select * from mytable",conn
ofield1 = request.form("ifield1") 'This is where I need to reflect the position of the row
if delete <> "" then
set rs.execute "delete from mytable where field1=ofield1"
end if
%>


<html
<body>
<form name="myform" action="myfile.asp" method=post>
<table>
<tr>
<%while not rs.eof%>

<input name=ifield1 type = text value="<% =rs("field1") %>">
<input name=ifield2 type = text value="<% =rs("field1") %>">
<input type=button value="delete">
</tr>
<% rs.movenext
wend %>
</table>
</form>
</body>
</html>


 
Old June 18th, 2005, 12:17 AM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a quick thought.
Often face with what I assume to be similar tasks I usually do some thing like this:
<table>
<tr>
<%i = 0%>
<%while not rs.eof
i = i + 1
tmpVar = rs("field1")
%>
<form name="myform" action="myfile.asp<%=i%>" method=post>
<input name=ifield1 type = hidden value="<% =tmpVar1 %>">
<input name=ifield1 type = hidden value="<% =tmpVar1 %>">
<input type=button value="delete">
</form>

<%rs.movenext%>
<%wend%>
</tr>
</table>

With out seeing your code it is tought to know the positions in yoour tables but the concept is to use variables to carry the values of the recordset this allows you to display and post them, also to include everything needed to complete your task in to the submit buttons cell.

Good Luck

 
Old June 18th, 2005, 09:32 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mozgheib
There are many ways to skin a cat, your way will work. I believe the more conventional way to achieve this is to pass a records unique ID instead of the row number.

The way casselj has illustrated will also work. IMO a bad pratice to have so many forms on a page. If you had 50 records in your record set, you are going to have 50 froms on the page. This is not ideal.

Your query is select * from mytable. Does this table have a unique auto incrementing primary key field? Even if you dont think you need it, put one in there call it ID (or what ever) then forget about it. Then when you want to edit, update and delete records things are much much easier.

I noticed you had your <tr> tag outside the loop. I am guessing you have not run the code? this is why I will be brief. Here is how I would handle it:

1..Add a hidden field outside your loop:
<input type="hidden" name="idToDelete" value="">

2..Inside your loop change your button to:
<input type="button" value="delete" onClick="SomeFunctionName(rs(0));">
Note: rs(0) is the record which represents the unique ID of the record. This may be called rs("fieldName") also.

3..Now in the head of your document inside JS tags (where are your <head></head><title></title> tags in your example? every page that has a user interface should have them):

<script language="javascript">
    function SomeFunctionName(idbeingPassed)
    {
        //you should place an alert here confirming the delete
        myForm.idToDelete.value = idbeingPassed;
        myForm.submit();
    }
</script>

now place this delete code above the following line:
set rs.open="select * from mytable",conn

if request.form("idToDelete") <> "" then
sql = "DELETE FROM mytable WHERE id=" & request.form("idToDelete") & ";"
end if

NOTE: ID should be replaced with the name of your unique field. If you dont place the delete above your initial select code the deleted record will still show.


Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
html table row id myself.panku ASP.NET 1.x and 2.0 Application Design 0 April 17th, 2008 01:56 PM
How to change the color of selected row of an HTML bhavna HTML Code Clinic 4 February 11th, 2007 09:22 PM
UPDATING 1 row with another row in same table rit01 SQL Server 2000 3 February 19th, 2006 08:55 AM
first row of a table Adam H-W SQL Language 2 January 11th, 2005 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.