Update button in table

08-15-2002, 03:04 PM

I need help. I am not sure exactly how to do something and I know one of you guys does. Or you can tell me where an example of this is and I will reverse engineer it for myself!

Here is the situation.

I am building a table in an asp from data in a table. One of those fields is a description field. I want to allow the user to edit and update that field from within the table.

I figured out how to make it a text input and put the data from the database into the text field in the table data spot. That's wasn't tough. The question is this, how do I create a button, in a later cell in the table in the same row as the edited field, that is the Update button? When they push this button, it updates that data in the database.

I am also trying to have one asp that runs all of the database functions like this and then goes back to the first page (with a redirect). I can't figure out how to dynamically create the button and send the data from the input text to the second page.

Any help would be appreciated!



08-15-2002, 03:43 PM
Enclose of all of the INPUT controls in a FORM and then have it bounce to a script that processes the information. Here's an example:<!-- Here, the "ID" (PrimaryKey in the db table) is inserted when the script is ran -->

<FORM METHOD=POST ACTION="dbaction.asp?method=update&ID=<%=RS("ID")%>">
</FORM>Then, in "dbaction.asp" you'd have something like this:
Set RS = Server.CreateObject("ADODB.Recordset")

Select Case request.querystring("method")

Case "update"
'Use the primary key to open this record
RS.Open _
"SELECT [Comments] " & _
"FROM [YourTable] " & _
"WHERE [PrimaryKey]=" & request.querystring("ID"), Application("CNN")

'Get the info from the submitting page and update
'the recordset with it
RS("Comments") = Replace(Request("txtComments"),"'","''")

strPage = "default.asp"

'** have other cases here

End Select

Set RS = Nothing

Response.Redirect strPageI do everything on one page like this with a "Select Case" statement so as to better consolidate everything -- meaning you don't have to have lots of indivdual .asp scripts to process things.

08-15-2002, 03:52 PM
Thanks for the reply!

In general, that is what I am trying to do.

The issue is that I have a table of buttons, each updating their row. Do I then need multiple <FORM> objects for each button?

This is what I am trying to do:

<td>Row 1 </td>
<td><input type="text" length="20" value="row 1 information"></td>
<td><input type="button" value="Update row 1"></td>
<td>Row 2 </td>
<td><input type="text" length="20" value="row 2 information"></td>
<td><input type="button" value="Update row 2"></td>
<td>Row 3 </td>
<td><input type="text" length="20" value="row 3 information"></td>
<td><input type="button" value="Update row 3"></td>

Therefore, when they push the button in row 1, only the "row 1 information" will be updated in the database. Do I need to create a <FORM> object around each row?

Good idea on the one asp idea. That is what I am trying to do! I am almost there except for this issue.



08-15-2002, 04:00 PM
Yeah, just use a FORM for each row. The SUBMIT button associated with each row tells the browser to store all of the information contained within that FORM for future reference.

A little redundant, I know. But I can't think of any other way to do it.

08-16-2002, 08:57 AM

that is what I needed to do!

I appreciate the help!


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum