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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture record id from table array within hyperlink address 1

Status
Not open for further replies.

SarahMH

MIS
May 16, 2003
28
0
0
GB
I need to capture the id of the record set to enable the edit button to go to the edit page displaying details of that record.
It is in an array which writes out the headings of the table then each row with an edit button (hyperlink with image - which should capture the id of that record, appending it to the hyperlink which will open the edit page for that record when the edit button is clicked.) at the beginning of each row of the table.

I cannot get it to work - can anyone help please:

Below is the function that creates the table:
function GetReport(chosenview)
'response.Write chosenview
sViews = chosenview

dim i, i2, intCounter,sArray,sText,strColor

intCounter = 0

sSql = "SELECT * from dbo.[" & sViews & "]"
'response.write sSql
'response.End


objRs.Open sSql, objConn, 3,3'adOpenStatic, adLockReadOnly, adCmdText
strColor = "white"
'create start of html table for data
if (not objRS.eof) OR (not objRS.bof) then
'if (not objRS.eof) then
sArray = objRS.GetRows()
response.write "<p>" & Ubound(sArray,2)+1 & " record(s)</p>"
response.write "<p><table id=""tablerecs"" border=""1"" cellpadding=""2"" cellspacing=""1"">"
response.write "<tr style=""background-color:#9999cc;"">"

'first row is header row


response.write "<th class=""smalltd""> </th>"
for i = 0 to objRS.fields.count-1
response.write "<th class=""smalltd""><b>" & objRS.fields(i).Name & "</b></th>"
next
response.write "</tr >"
'add table data rows

'the HREF below is the section that doesn't work, i have included two of my trys.

intCounter = Ubound(sArray,2)

'response.write "<td class=""smalltd""><a title=""Click to edit this record"" href="" d="& sArray(i2,i) &"&from=drilldown"" >" & "<img src=""/Images/edit.gif"" height=""15"" width=""28"" /></a></td>"

or

response.write "<tr><td class=""smalltd""><a title=""Click to edit this record"" href="" "& sArray(i).value & "><img src=""/Images/edit.gif"" height=""15"" width=""28"" /></a></td>"

' records - id is the first field in the recordset

for i2 = 0 to Ubound(sArray,1)

sText = isnullval(sArray(i2,i))
response.write "<td class=""smalltd"">" & sText & "</td>"
next
response.write "</tr>"


next

response.write "</table>"

Many thanks!
 
a little bit simplefied:

Code:
<%

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open <connection string>

sSql = "SELECT * from dbo.[" & sViews & "]" 
Set objRs = Server.CreateObject("ADODB.Recordset")

objRs.Open sSql, oConn

if (not objRS.eof) OR (not objRS.bof) then
 sArray = objRS.GetRows()
 response.write Ubound(sArray,2)+1 & " record(s)<br>"
 response.write "<table border=""1"" cellpadding=""2"" cellspacing=""1"">"
 response.write "<tr>"
 response.write "<th>Action</th>"
 for i = 0 to objRS.fields.count-1
  response.write "<th><b>" & objRS.fields(i).Name & "</b></th>"
 next
 response.write "</tr>"
 
 objRS.movefirst
 do while not objRS.eof
  response.write "<tr><td ><a href=""Edit.asp?id=" & objRS(2) & """>Edit</a></td>"
  for i = 0 to ubound(sArray)
    response.Write "<td>" & objRS(i) & "</td>"  
  next
  response.Write "</tr>"
  objRS.movenext
 loop
 response.Write "</table>"
end if
objRS.close
oConn.close

%>

(i presume in ALL your view's field 1 is the ID field...)
 
Thank you so very much foxbox!!!

It works perfectly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top