This topic is locked

Master-Detail Link - Only on field exist

2/20/2007 4:09:01 PM
ASPRunnerPro General questions
V
VORONOY author

Hello,
How do I make Master-Detail link show up in row only if record exist (like primary ID) and hide it if no record? By default it links you to List page "No records found

"
I need to put make this code somehow.. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4660&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
That's what I tried, but it did not work.
strSQLExists = "select ID from dbo.Table2 where ID = 'This should be variable that = ID from Table 1 (ID in the row in Table1_list.asp)' "

set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection
if not rsExists.eof then

value=""

row.Add col & "Change_value", "Exists"
else

value=""

row.Add col & "Change_value", "Not-Exists"
end if

rsExists.Close : set rsExists = Nothing
Then I tried to assign {$row.1Change_value} in Table1_list.html template instead of actual Master-Detail link.
Thank you

J
Jane 2/21/2007

Hi,
you can do the following:

1.edit SQL query of the MasterTable on the Edit SQL query tab. Here is a sample:

select ID,

ID as link,

...

from TableName

  1. check off this field on the List page only on the Choose fields tab
  2. select Custom for this field on the "View as" settings dialog on the Visual Editor tab and add your code in it.

    Here is a sample:
    str = "select count(*) from DetailTable where ForeignKey="&strValue

    Set rsTemp = server.CreateObject("ADODB.Recordset")

    rsTemp.open str, dbConnection
    if not rsTemp(0)=0 then

    strValue = "<a href=""DetailTable_list.asp?mastertable=MasterTable&masterkey1=" & strValue & """>DetailTable</A>"

    else

    strValue=""

    end if

    rsTemp.Close : set rsTemp = Nothing



where ForeignKey is your actual field name where foreign key is stored, MasterTable and DetailTable are your actual table names.

V
VORONOY author 2/21/2007

Thanks Jane!
I tried it, but have no luck with it.
Link is showing up in Master Table, but with no values.
I think the problem with this line:
str = "select count(*) from dbo.Details where ID="&strValue
Do I need to declare strValue anywere?
Thanks

V
VORONOY author 2/21/2007

I got it
str = "select count(*) from Detailstable where ID ='" & strValue & "'"

Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
Thanks!