Help with Dynamic repeater...

  • Thread starter John Pether (john@
  • Start date
J

John Pether (john@

Hi

I have a page that displays business listings. I have a repeater with dynamic text and in the 4th column I have an email and website link. Both display properly but I need to have one take precedent over the other, so if ("www") is not null then it should be displayed and the email shouldn't. I also need some script to only display either if the field is not null.

This is not really my thing, and I have been trying to figure this out all day so any help would be greatly appreciated:)

John Pether

<code>
<%
While ((Repeat1__numRows <> 0) AND (NOT listings.EOF))
%>
<tr>
<td><%=(listings.Fields.Item("BusinessName").Value)%><br /> <%=(listings.Fields.Item("Address1").Value)%><%=(listings.Fields.Item("Address2").Value)%><br /> <%=(listings.Fields.Item("SubPost").Value)%><br /> </td>
<td><%=(listings.Fields.Item("Phone").Value)%></td>
<td><%=(listings.Fields.Item("Fax").Value)%></td>
<td><a href="mailto:<%=(listings.Fields.Item("Email").Value)%>">Email Us</a><br>><a href="<%=(listings.Fields.Item("WWW").Value)%>">Visit Us</a></td>
<td</td>
</tr>
<tr>
<td colspan=4><hr></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
listings.MoveNext()
Wend
%>

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
K

Ken Schaefer

Change:
<td><a href="mailto:<%=(listings.Fields.Item("Email").Value)%>">Email
Us</a><br>><a href="<%=(listings.Fields.Item("WWW").Value)%>">Visit
Us</a></td>

to

<td><%=GetContactDetails(listings)%></td>

and later on, paste:

<%
Function GetContactDetails( _
ByRef listings _
)

If isNull(listings.Fields.Item("WWW") then
GetContactDetails = "<a href=""mailto:""" &
listings.Fields.Item("Email").Value & """>"
Else
GetContactDetails = "<a href=""mailto:""" &
listings.Fields.Item("WWW").Value & """>"
End If

End Function
%>


Note: I do not recommend this, as you're passing a recordset object around
to the function. Better would be, if you have to keep the recordset object,
to allocate the variables to strings, then pass in the strings, eg:

<%
strEmail = listings.Fields.Item("Email").Value
strWWW = listings.Fields.Item("WWW").Value
%>
<td><%=GetContactDetails(strEmail, strWWW)%></td>

, and then change the first line of the function to:

Function GetContactDetails( _
ByVal strEmail, _
ByVal strWWW _
)

HTH

Cheers
Ken




: Hi
:
: I have a page that displays business listings. I have a repeater with
dynamic text and in the 4th column I have an email and website link. Both
display properly but I need to have one take precedent over the other, so if
("www") is not null then it should be displayed and the email shouldn't. I
also need some script to only display either if the field is not null.
:
: This is not really my thing, and I have been trying to figure this out all
day so any help would be greatly appreciated:)
:
: John Pether
:
: <code>
: <%
: While ((Repeat1__numRows <> 0) AND (NOT listings.EOF))
: %>
: <tr>
: <td><%=(listings.Fields.Item("BusinessName").Value)%><br />
<%=(listings.Fields.Item("Address1").Value)%><%=(listings.Fields.Item("Addre
ss2").Value)%><br /> <%=(listings.Fields.Item("SubPost").Value)%><br />
</td>
: <td><%=(listings.Fields.Item("Phone").Value)%></td>
: <td><%=(listings.Fields.Item("Fax").Value)%></td>
: <td><a
href="mailto:<%=(listings.Fields.Item("Email").Value)%>">Email Us</a><br>><a
href="<%=(listings.Fields.Item("WWW").Value)%>">Visit Us</a></td>
: <td</td>
: </tr>
: <tr>
: <td colspan=4><hr></td>
: </tr>
: <%
: Repeat1__index=Repeat1__index+1
: Repeat1__numRows=Repeat1__numRows-1
: listings.MoveNext()
: Wend
: %>
:
: **********************************************************************
: Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
: Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
J

John Pether (john@

ok, great thanks for your help. I had a few probs with the code, syntax etc...but got through that....however nuthing is appearing on the page. I have used the code below but even though there is an entry in the www field, nothing is showing on the page.

I also do not see how this would allow "www" to take precedent over "email" if they both have data in the fields....

Once again thanks for your help and I hope you/someone can help me get this working:)

<td valign="top"><%=GetContactDetails(strEmail, strWWW)%></td>

<%
strEmail = listings.Fields.Item("Email").Value
strWWW = listings.Fields.Item("WWW").Value
%>
<%
Function GetContactDetails( _
ByVal strEmail, _
ByVal strWWW _
)

If isNull(listings.Fields.Item("WWW")) then
GetContactDetails = "<a href=""mailto:""" & listings.Fields.Item("Email").Value & """>"
Else
GetContactDetails = "<a href=""http://""" & listings.Fields.Item("WWW").Value & """>"
End If

End Function
%>

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
K

Ken Schaefer

Hi,

You need to assign the values to the variables *before* you call the
function, otherwise when you call the function you are passing in two
"nothing"s.

ie:

<%
strEmail = listings.Fields.Item("Email").Value
strWWW = listings.Fields.Item("WWW").Value
%>
<td valign="top"><%=GetContactDetails(strEmail, strWWW)%></td>

The function GetContactDetails() can be located anywhere in your code.

Also, I made a mistake with the function. Rewrite it like this:

<%
Function GetContactDetails( _
ByVal strEmail, _
ByVal strWWW _
)

If isNull(strWWW) then
GetContactDetails = "<a href=""mailto:""" & strEmail &
""">Email</a>"
Else
GetContactDetails = "<a href=""http://""" & strWWW & """>WWW</a>"
End If

End Function
%>

So, it checks strWWW. If that is NULL, then it returns the email address.
You may wish to put an additional check in the in case strEmail is *also*
NULL, in which case you might want to return "no contact details" or
something.

If strWWW is not NULL, then it returns the link.

Cheers
Ken




: ok, great thanks for your help. I had a few probs with the code, syntax
etc...but got through that....however nuthing is appearing on the page. I
have used the code below but even though there is an entry in the www field,
nothing is showing on the page.
:
: I also do not see how this would allow "www" to take precedent over
"email" if they both have data in the fields....
:
: Once again thanks for your help and I hope you/someone can help me get
this working:)
:
: <td valign="top"><%=GetContactDetails(strEmail, strWWW)%></td>
:
: <%
: strEmail = listings.Fields.Item("Email").Value
: strWWW = listings.Fields.Item("WWW").Value
: %>
: <%
: Function GetContactDetails( _
: ByVal strEmail, _
: ByVal strWWW _
: )
:
: If isNull(listings.Fields.Item("WWW")) then
: GetContactDetails = "<a href=""mailto:""" &
listings.Fields.Item("Email").Value & """>"
: Else
: GetContactDetails = "<a href=""http://""" &
listings.Fields.Item("WWW").Value & """>"
: End If
:
: End Function
: %>
:
: **********************************************************************
: Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
: Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
J

John Pether (john@

Great!!

Thanks for all your help, I've learnt loads:)

I have tried as you said to add another section to deal with to nulls but it gives an error.
I added another if statement:
If isNull(strWWW, strEmail) then
GetContactDetails = "No Internet Details"
End If

I presume from the error that you cannot pass two arguments to isNull, how should I do this?

John

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top