Conditional code in Repeaters

E

Evan M.

Here's my situation:

I'm creating a blog-like application for my company to do some simple
news updates about new products in and the like that is only used
internally on the intranet.

I have an XML file storing each article that I'm reading into a
DataSet, using a DataView for filtering the DataSet if some search-text
is entered, and a Repeater control to display the data from the
DataView.

The problem that I'm having is that the XML/DataSet also contains path
information to secondary pages, such as PDFs, images, etc., but this
data does not exist for each entry. I need to be able to check if a
piece of data exists (or a value check on an 'exists' column), then add
in additional HTML to do such things as add the image, or set the title
to link to the PDF. Pseudo-code example below.

Anyone have any idea's about how I'd go about doing this? Thanks
Evan M.

<itemtemplate>
<% if DataBinder.Eval(Container.DataItem, "image_path") != null) then
%>
<img src="<%# DataBinder.Eval(Container.DataItem, "image_path") %>"
/>
<% end if %>
<p class="Heading2">
<% if (DataBinder.Eval(Container.DataItem, "pdf_path") != null) then%>
<a href="<%# DataBinder.Eval(Container.DataItem, "pdf_path")%>"><%#
DataBinder.Eval(Container.DataItem, "title") %></a>
<% else %>
<%# DataBinder.Eval(Container.DataItem, "title") %>
<% end if %>
</p>
<div class="Small"><%# DataBinder.Eval(Container.DataItem, "desc")
%></div>
</itemtemplate>
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top