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

Conitional statements in listview with eval

Status
Not open for further replies.

stinkybee

Programmer
May 15, 2001
218
GB
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
 
Please show the entire markup for the listview where you have this code
 
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">&rArr; 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")%>">&rArr; 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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top