×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Conitional statements in listview with eval

Conitional statements in listview with eval

Conitional statements in listview with eval

(OP)
I am trying to either show or hide a link based on the value of an Eval within my list view

I would like to do something like this

CODE

<% if Eval("value") <> "" then %>
display link
<% end if %> 

but I cannot use these tags in a listview

I have also tried to do it based on the visible property of the anchor tag

CODE

<a href="mylink.aspx" visible="<%# iif(Eval("value") = "", "false", "true")%>">link</a> 

but I get this error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.


Any ideas for this?

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneysurveys.co.uk
http://www.free-money-resource.com

RE: Conitional statements in listview with eval

Please show the entire markup for the listview where you have this code

RE: Conitional statements in listview with eval

(OP)
Here's the code

CODE

<asp:ListView ID="ListView2" runat="server" DataSourceID="AccessDataSource2">
	<ItemTemplate>			
		<asp:AccessDataSource id="AccessDataSource3" runat="server" DataFile="db/reviews.mdb" SelectCommand="SELECT * FROM programmes;">
		</asp:AccessDataSource>	
		<div class="review_buttons">
			<div class="review_button">
				<a href="<%# Eval("programmes_link") %>" target="_blank">⇒ Signup</a>
			</div>
			<div class="review_button review_button_show" id="review_button<%# Eval("programmes_id")%>">
													
				<a href="javascript:CollapseExpand('<% Eval("programmes_id")%>');" visible="<%# IIf(Eval("programmes_review")<>"", "true", "false")%>">⇒ Show Review</a>
														
			</div>
		</div>
								
	</ItemTemplate>
							
	<LayoutTemplate>							<span runat="server" id="itemPlaceholder" />                  
	</LayoutTemplate>		
</asp:ListView> 

So I need to only display the second link if there is a value in "programmes_review".

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneysurveys.co.uk
http://www.free-money-resource.com

RE: Conitional statements in listview with eval

(OP)
Thanks for the pointer. I was able to work it out from the link. There were a couple of issues but managed to do it by calling a function that set the style property of the containing div.

CODE

<div class="review_button review_button_show" id="review_button<%# Eval("programmes_id")%>" style="Display:<%# ShowButton(Eval("programmes_review"))%>">
<a href="javascript:CollapseExpand('<%# Eval("programmes_id")%>');">Show Review</a>
</div> 

CODE

Function ShowButton(ByVal value As String) As string
   If value = "" Then
       Return "none"
    Else
       Return "true"
    End If	
End Function 

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneysurveys.co.uk
http://www.free-money-resource.com

RE: Conitional statements in listview with eval

Glad you got it working

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close